:root {
  --mfs-blue: #1e3a8a;
  --mfs-blue-dark: #152961;
  --mfs-blue-light: #2d4ea8;
  --mfs-blue-50: #eef2fa;
  --mfs-green: #00966E;
  --mfs-red: #D62612;
  --mfs-bg: #f4f6fa;
  --mfs-text: #1f2937;
  --mfs-muted: #6b7280;
  --mfs-border: #e5e7eb;
  --mfs-card: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--mfs-bg);
  color: var(--mfs-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--mfs-blue); text-decoration: none; }
a:hover { color: var(--mfs-blue-light); }

.layout { display: flex; min-height: 100vh; }

/* ============ SIDEBAR ============ */
.sidebar {
  width: 240px;
  background: var(--mfs-blue-dark);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-logo {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--mfs-blue);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: 1px;
  border: 2px solid #fff;
  position: relative;
  overflow: hidden;
}
.sidebar-logo span { position: relative; z-index: 2; }
.sidebar-logo .flag {
  position: absolute; left: 0; right: 0; top: 50%; bottom: 0;
  background: linear-gradient(to bottom, #00966E 0%, #00966E 50%, #D62612 50%, #D62612 100%);
  opacity: 0.55;
}
.sidebar-brand-text { line-height: 1.15; }
.sidebar-brand-text .t1 { font-weight: 700; font-size: 13px; letter-spacing: .5px; }
.sidebar-brand-text .t2 { font-size: 11px; opacity: .65; }

.sidebar-section {
  padding: 14px 18px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.45);
}
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.85);
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar a.nav-link .nav-badge {
  margin-left: auto;
  background: var(--mfs-red);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-link.active {
  background: rgba(255,255,255,.08);
  color: #fff;
  border-left-color: var(--mfs-red);
  font-weight: 600;
}
.sidebar a.nav-link .ico { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: rgba(255,255,255,.4); }

/* ============ MAIN ============ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--mfs-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.topbar .crumbs { color: var(--mfs-muted); font-size: 13px; }
.topbar .crumbs .sep { margin: 0 6px; opacity: .5; }
.topbar .crumbs strong { color: var(--mfs-text); }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.tenant-pill {
  background: var(--mfs-blue-50);
  color: var(--mfs-blue);
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.topbar-logout {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--mfs-red);
  color: #fff;
  font-size: 13px; font-weight: 600;
  text-decoration: none;
  transition: filter .15s;
  border: 1px solid var(--mfs-red);
}
.topbar-logout:hover {
  filter: brightness(0.9);
  color: #fff;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--mfs-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}

.content { padding: 22px 26px; flex: 1; }
.page-h {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px; gap: 16px; flex-wrap: wrap;
}
.page-h h1 { font-size: 22px; margin: 0; font-weight: 700; }
.page-h .sub { color: var(--mfs-muted); font-size: 13px; margin-top: 3px; }

/* ============ CARDS ============ */
.card-mfs {
  background: var(--mfs-card);
  border: 1px solid var(--mfs-border);
  border-radius: 10px;
  padding: 18px;
}
.card-mfs.tight { padding: 0; }
.card-h {
  padding: 14px 18px;
  border-bottom: 1px solid var(--mfs-border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600;
}
.card-h .actions { display: flex; gap: 8px; }
.card-b { padding: 18px; }

/* ============ KPI ============ */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: #fff;
  border: 1px solid var(--mfs-border);
  border-radius: 10px;
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.kpi .lbl { font-size: 12px; color: var(--mfs-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 12px; margin-top: 4px; }
.kpi .delta.up { color: var(--mfs-green); }
.kpi .delta.down { color: var(--mfs-red); }
.kpi .ico-bg {
  position: absolute; right: -8px; top: -8px;
  font-size: 70px; opacity: .07; color: var(--mfs-blue);
  font-weight: 900;
}

/* ============ TABLES ============ */
table.mfs {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
table.mfs th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--mfs-muted);
  background: #fafbfd;
  border-bottom: 1px solid var(--mfs-border);
}
table.mfs th.right  { text-align: right; }
table.mfs th.center { text-align: center; }
table.mfs td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--mfs-border);
  vertical-align: middle;
}
table.mfs tr:last-child td { border-bottom: 0; }
table.mfs tr:hover td { background: #fafbfd; }

/* ============ BADGES ============ */
.badge-mfs {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.b-green { background: #e6f7f0; color: var(--mfs-green); }
.b-red   { background: #fdecea; color: var(--mfs-red); }
.b-blue  { background: var(--mfs-blue-50); color: var(--mfs-blue); }
.b-amber { background: #fff4d6; color: #a86a00; }
.b-gray  { background: #eef0f3; color: #555; }
.b-purple{ background: #f5f3ff; color: #6d28d9; }   /* статус „иска предплатени" */

/* ============ BUTTONS ============ */
.btn-mfs {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--mfs-blue);
  color: #fff;
  border: 0;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-mfs:hover { background: var(--mfs-blue-light); color: #fff; }
.btn-mfs.gh { background: #fff; color: var(--mfs-blue); border: 1px solid var(--mfs-border); }
.btn-mfs.gh:hover { background: var(--mfs-blue-50); }
.btn-mfs.danger { background: var(--mfs-red); }
.btn-mfs.sm { padding: 5px 10px; font-size: 12px; }
.btn-mfs.success { background: var(--mfs-green); }

/* ============ FORMS ============ */
.form-row { display: grid; grid-template-columns: 200px 1fr; gap: 10px 16px; align-items: center; margin-bottom: 12px; }
.form-label { color: var(--mfs-muted); font-size: 13px; }
.inp, select.inp, textarea.inp {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--mfs-border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
}
.inp:focus, select.inp:focus, textarea.inp:focus { outline: none; border-color: var(--mfs-blue); }
.help { font-size: 12px; color: var(--mfs-muted); margin-top: 4px; }

/* ============ FILTER BAR ============ */
.filterbar {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--mfs-border);
  border-radius: 10px;
  margin-bottom: 14px;
  align-items: center;
}
.filterbar .inp { width: auto; min-width: 140px; }

/* ============ SCHEDULE GRID ============ */
.sched-grid {
  display: grid;
  grid-template-columns: 80px repeat(7, 1fr);
  background: #fff;
  border: 1px solid var(--mfs-border);
  border-radius: 10px;
  overflow: hidden;
}
.sched-grid .cell { border-bottom: 1px solid var(--mfs-border); border-right: 1px solid var(--mfs-border); padding: 6px; min-height: 56px; font-size: 12px; }
.sched-grid .cell.h { background: #fafbfd; font-weight: 600; text-align: center; padding: 10px 6px; color: var(--mfs-muted); }
.sched-grid .cell.time { background: #fafbfd; text-align: right; color: var(--mfs-muted); border-right: 1px solid var(--mfs-border); padding-right: 10px; }
.sched-grid .ev {
  background: var(--mfs-blue-50);
  border-left: 3px solid var(--mfs-blue);
  padding: 5px 7px;
  border-radius: 5px;
  margin-bottom: 3px;
  cursor: pointer;
}
.sched-grid .ev .t { font-weight: 600; font-size: 12px; color: var(--mfs-blue); }
.sched-grid .ev .l { font-size: 11px; color: var(--mfs-muted); }
.sched-grid .ev.red    { background: #fdecea; border-color: var(--mfs-red); }
.sched-grid .ev.red .t { color: var(--mfs-red); }
.sched-grid .ev.green  { background: #e6f7f0; border-color: var(--mfs-green); }
.sched-grid .ev.green .t { color: var(--mfs-green); }
.sched-grid .ev.amber  { background: #fff4d6; border-color: #a86a00; }
.sched-grid .ev.amber .t { color: #a86a00; }

/* ============ COMMENTS / FEED ============ */
.feed { display: flex; flex-direction: column; gap: 10px; }
.feed-item {
  border: 1px solid var(--mfs-border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafbfd;
}
.feed-item .meta { font-size: 11px; color: var(--mfs-muted); margin-bottom: 4px; }
.feed-item .body { font-size: 13.5px; }
.feed-item.cc { border-left: 3px solid var(--mfs-red); }

/* ============ DUAL COLUMN ============ */
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv .k { color: var(--mfs-muted); }
.kv .v { font-weight: 500; }

/* ============ LOGIN ============ */
.login-bg {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--mfs-blue) 0%, var(--mfs-blue-dark) 100%);
}
.login-card {
  width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--mfs-blue);
  border: 4px solid #fff;
  box-shadow: 0 0 0 1px var(--mfs-blue-light);
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.login-logo span {
  position: relative; z-index: 2;
  font-weight: 900; font-size: 24px; color: #fff; letter-spacing: 2px;
}
.login-logo .flag {
  position: absolute; left: 0; right: 0; top: 50%; bottom: 0;
  background: linear-gradient(to bottom, #00966E 0%, #00966E 50%, #D62612 50%, #D62612 100%);
  opacity: .5;
}
.login-card h2 { text-align: center; margin: 0 0 4px; font-size: 18px; }
.login-card .sub { text-align: center; color: var(--mfs-muted); font-size: 13px; margin-bottom: 22px; }

/* ============ MISC ============ */
.row-flex { display: flex; gap: 14px; flex-wrap: wrap; }
.row-flex > * { flex: 1; min-width: 240px; }
.muted { color: var(--mfs-muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.gap-8 { display: flex; gap: 8px; }
.tag { display: inline-block; padding: 2px 8px; background: var(--mfs-blue-50); color: var(--mfs-blue); border-radius: 4px; font-size: 12px; }
hr.soft { border: 0; border-top: 1px solid var(--mfs-border); margin: 14px 0; }

/* ============ MOBILE ============ */
.hamburger {
  display: none;
  background: transparent; border: 0; color: var(--mfs-text);
  font-size: 22px; padding: 6px 10px; cursor: pointer;
}
@media (max-width: 800px) {
  /* Защита от horizontal scroll на цялата страница */
  html, body { max-width: 100vw; overflow-x: hidden; }
  .content { max-width: 100%; min-width: 0; }
  /* Grid items да не разпъват колонката над тяхното съдържание */
  .two-col > * { min-width: 0; }
  .kpis > * { min-width: 0; }
  /* Дълги думи/URL-и да се пречупват вместо да разпъват клетка */
  .feed-item .body, .card-mfs .card-b, .kv .v { word-wrap: break-word; overflow-wrap: anywhere; }
  /* Fixed topbar на мобилно — хамбургер + breadcrumbs винаги залепени горе */
  .topbar {
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 40;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
  }
  /* Compensate за фиксирания topbar (56px) — content започва под него */
  .main { padding-top: 56px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s;
    z-index: 50;
    width: 250px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-scrim {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 49;
  }
  .hamburger { display: inline-flex; align-items: center; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .crumbs { font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tenant-pill { display: none !important; }
  .user-chip > div:not(.avatar) { display: none; }
  .content { padding: 14px 12px; }
  .page-h h1 { font-size: 18px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .val { font-size: 20px; }
  .two-col { grid-template-columns: 1fr !important; }
  .form-row { grid-template-columns: 1fr; gap: 4px; }
  .filterbar { gap: 6px; padding: 10px; }
  .filterbar .inp { width: 100%; min-width: 0; flex: 1 1 140px; }
  table.mfs { font-size: 12.5px; }
  table.mfs th, table.mfs td { padding: 9px 8px; }
  .sched-grid { grid-template-columns: 60px repeat(7, minmax(120px, 1fr)); overflow-x: auto; }

  /* Универсален responsive table — превръща таблици с data-label в карти */
  table.mfs.stack-mobile { display: block; }
  table.mfs.stack-mobile thead { display: none; }
  table.mfs.stack-mobile tbody, table.mfs.stack-mobile tfoot { display: block; }
  table.mfs.stack-mobile tr {
    display: block;
    border: 1px solid var(--mfs-border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  table.mfs.stack-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 4px 0;
    border: none;
    font-size: 14px;
  }
  table.mfs.stack-mobile td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--mfs-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .4px;
    margin-right: 10px;
  }
  table.mfs.stack-mobile td:not([data-label])::before { content: ""; }
  /* В stack-mobile карта стойността не се пречупва (запазва "1 234.56 €" на един ред) */
  table.mfs.stack-mobile td.right { text-align: right; }
  table.mfs.stack-mobile td { white-space: normal; }
  table.mfs.stack-mobile td > strong,
  table.mfs.stack-mobile td.right { white-space: nowrap; }

  /* Scroll-mobile — таблицата получава хоризонтален скрол вместо stack */
  .card-mfs > table.mfs.scroll-mobile,
  .card-mfs .card-b > table.mfs.scroll-mobile {
    display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }

  /* Card-mfs leko по-tight padding на мобилно */
  .card-mfs { padding: 12px; }
  .card-mfs.tight { padding: 10px; }
  .card-mfs .card-h {
    flex-wrap: wrap; gap: 8px;
  }

  /* Page-h на мобилно — actions падат под title */
  .page-h { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-h .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
  .page-h .actions > * { flex: 0 1 auto; }

  /* KV блок — по-компактен */
  .kv { grid-template-columns: 1fr; gap: 4px 0; }
  .kv .k { padding-top: 4px; font-weight: 600; }
  .kv .v { padding-bottom: 8px; padding-left: 8px; border-bottom: 1px dashed var(--mfs-border); }

  /* Topbar logout — само иконка на мобилно */
  .topbar-logout span,
  .topbar-logout .logout-text { display: none; }
  .topbar-logout { padding: 0 12px; }
}

/* ============ REPORT (PRINTABLE) ============ */
.report-page {
  max-width: 1024px;
  margin: 24px auto;
  background: #fff;
  border: 3px solid var(--mfs-red);
  padding: 28px 32px;
  font-size: 13px;
}
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 30px; margin-bottom: 22px; }
.report-logo {
  width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.report-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
/* Стари fallback правила за случай ако някъде се ползва SVG placeholder */
.report-logo span { font-weight: 900; color: #fff; letter-spacing: 1px; font-size: 16px; }
.report-logo .flag { display: none; }
.report-title { flex: 1; font-size: 22px; font-weight: 700; padding-top: 16px; }
.report-meta { text-align: right; line-height: 1.45; }
.report-meta .name { font-size: 18px; font-weight: 700; }
.report-meta .small { font-size: 12px; color: var(--mfs-muted); }
.report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table thead th {
  background: var(--mfs-blue);
  color: #fff;
  text-align: left;
  padding: 7px 8px;
  font-weight: 600;
  font-size: 11.5px;
}
.report-table tbody td { padding: 7px 8px; border-bottom: 1px solid #e5e7eb; }
.report-table .totals-row td {
  background: var(--mfs-blue); color: #fff; font-weight: 700;
  padding: 8px;
}
.report-table .subtotal-row td {
  background: var(--mfs-blue); color: #fff; padding: 8px;
}

/* ============ SWAP / OVERVIEW ============ */
.coach-cell { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--mfs-blue-50); border-radius: 6px; font-size: 12.5px; }
.coach-cell .x { color: var(--mfs-red); cursor: pointer; font-weight: 700; }
.coach-cell.swap { background: #fff4d6; border: 1px dashed #a86a00; }
.coach-cell.empty { background: #fdecea; color: var(--mfs-red); font-weight: 600; }
