/* MoneyTeam design system — tokens + components (see ARCHITECTURE.md "UI / design system") */
:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #0f766e;
  --primary-600: #115e59;
  --primary-50: #ecfdf5;
  --primary-100: #d1fae5;
  --accent: #f59e0b;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --ok: #16a34a;
  --ok-50: #f0fdf4;
  --warn: #d97706;
  --warn-50: #fffbeb;
  --info: #2563eb;
  --info-50: #eff6ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 236px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
  --content-max: 1280px;
  --t: 150ms ease;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
}

/* ---------- reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
[x-cloak] { display: none !important; }
a { color: var(--primary); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--primary-600); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
h2 { font-size: 20px; } h3 { font-size: 15px; }
p { margin: 0 0 var(--s-3); }
code { font-family: var(--mono); font-size: 12.5px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }
.icon { flex: none; vertical-align: -3px; }
.muted { color: var(--muted); }
.text-sm { font-size: 12.5px; }
.mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mb-4 { margin-bottom: var(--s-4); }
.ml-auto { margin-left: auto; }
.flex { display: flex; align-items: center; gap: var(--s-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); align-items: start; }
.grid-2-wide { grid-template-columns: 2fr 1fr; }
/* Grid items default to min-width:auto, so a wide table would push the track (and the page)
   past the viewport. Let the track shrink; .table-wrap stays the only horizontal scroller. */
.grid-2 > *, .grid-2-wide > * { min-width: 0; }
@media (max-width: 900px) { .grid-2, .grid-2-wide { grid-template-columns: 1fr; } }

/* ---------- shell layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  transition: width var(--t), transform var(--t); z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); padding: 0 var(--s-4); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand:hover { color: var(--text); }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none;
  background: var(--primary); color: #fff; border-radius: 8px; font-weight: 800; font-size: 15px;
}
.brand-name { white-space: nowrap; }
.sidebar-close { display: none; }
.nav { flex: 1; padding: var(--s-3) var(--s-2); overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; white-space: nowrap; border: 0; background: none; cursor: pointer;
  font: inherit; width: 100%; text-align: left; transition: background var(--t), color var(--t);
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-50); color: var(--primary); }
.nav-item .icon { width: 18px; height: 18px; }
.sidebar-footer { padding: var(--s-2); border-top: 1px solid var(--border); }
html.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.sidebar-collapsed .nav-label, html.sidebar-collapsed .brand-name { display: none; }
html.sidebar-collapsed .nav-item { justify-content: center; padding: 10px; }
html.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-6);
  background: rgba(255,255,255,.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }
.topbar-menu { display: none; }
.topbar-tenant { font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-tenant-static { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-6); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 0; background: none; color: var(--muted); cursor: pointer; transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* avatar + dropdown */
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-100); color: var(--primary-600); font-weight: 700; font-size: 12px; letter-spacing: .02em;
}
.avatar-sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar-btn { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.avatar-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dropdown { position: relative; }
.dropdown-trigger { gap: 6px; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 50;
}
.menu-right { left: auto; right: 0; }
.menu-heading { padding: 6px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 6px;
  color: var(--text); background: none; border: 0; cursor: pointer; font: inherit; text-align: left;
  transition: background var(--t);
}
.menu-item:hover { background: var(--bg); color: var(--text); }
.menu-item.active { color: var(--primary); font-weight: 500; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-user { padding: 8px 10px; }
.menu-user-name { font-weight: 600; }
.menu-user-email { color: var(--muted); font-size: 12.5px; }

/* ---------- page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.page-heading { font-size: 22px; }
/* The button row must wrap, otherwise two or three actions push the page past a phone viewport. */
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); flex: 0 1 auto; min-width: 0; }
.section-title { margin: var(--s-8) 0 var(--s-3); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-4); }

/* ---------- card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--s-5);
}
.card-flush { padding: 0; overflow: hidden; }
.card-title { margin-bottom: var(--s-4); font-size: 15px; }
.stack { min-width: 0; }
.stack > * + * { margin-top: var(--s-4); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; line-height: 1.2;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform var(--t);
}
.btn:hover { background: var(--bg); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--surface); border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-50); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn.disabled, .btn:disabled { opacity: .5; pointer-events: none; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.5; background: var(--primary-50); color: var(--primary-600);
  white-space: nowrap; vertical-align: middle;
}
.badge-ok { background: var(--ok-50); color: var(--ok); }
.badge-warn { background: var(--warn-50); color: var(--warn); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-info { background: var(--info-50); color: var(--info); }
.badge-muted { background: #f3f4f6; color: var(--muted); }

/* ---------- table ---------- */
.table-wrap { overflow: auto; max-height: 70vh; border-radius: var(--radius); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: #f9fafb; color: var(--muted);
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
.table tbody tr:nth-child(even) { background: #fafafa; }
.table tbody tr:hover { background: var(--primary-50); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .row-link { color: inherit; font-weight: 500; }
.cell-user { display: flex; align-items: center; gap: 8px; }
.inline-form { display: inline-block; margin: 0; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4) var(--s-5); }
.form-grid .span-2 { grid-column: span 2; }
.form-stack { display: flex; flex-direction: column; gap: var(--s-4); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .help, .help { font-size: 12px; color: var(--muted); margin: 0; }
.field .error { font-size: 12px; color: var(--danger); }
.input, .select, .textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; line-height: 1.4;
  transition: border-color var(--t), box-shadow var(--t);
}
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
.input::placeholder, .textarea::placeholder { color: #9ca3af; }
.input.is-invalid, .select.is-invalid { border-color: var(--danger); }
.input-static { background: var(--bg); color: var(--muted); }
.select { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; }
.select-sm { padding: 4px 28px 4px 8px; font-size: 12.5px; width: auto; }
.textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; gap: var(--s-2); justify-content: flex-end; padding-top: var(--s-1); }
.form-stack .form-actions { justify-content: flex-start; }
.form-grid .form-actions { justify-content: flex-start; }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid; margin-bottom: var(--s-4); font-size: 13.5px; }
.alert-danger { background: var(--danger-50); border-color: #fecaca; color: #991b1b; }
.alert-ok { background: var(--ok-50); border-color: #bbf7d0; color: #166534; }
.alert-list { margin: 0; padding-left: 18px; }

/* ---------- kpi ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: var(--s-4) var(--s-5); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi-delta { font-size: 12px; color: var(--muted); }
.kpi-delta.up { color: var(--ok); } .kpi-delta.down { color: var(--danger); }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- progress ---------- */
.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width 300ms ease; }
.progress-bar.warn { background: var(--warn); } .progress-bar.danger { background: var(--danger); }
.progress-row { display: flex; align-items: center; gap: var(--s-3); }
.progress-row .progress { flex: 1; }
.progress-row .num { min-width: 48px; font-size: 12.5px; color: var(--muted); }

/* ---------- tabs ---------- */
.tabs-nav { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--s-5); overflow-x: auto; }
.tab {
  padding: 10px 14px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: color var(--t), border-color var(--t);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-count { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--bg); font-size: 11px; color: var(--muted); }

/* ---------- empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--s-8) var(--s-4); gap: var(--s-2); }
.empty-lg { padding: 64px var(--s-4); }
.empty-sm { padding: var(--s-4); }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--primary-50); color: var(--primary); margin-bottom: var(--s-2); }
.empty-title { font-size: 16px; }
.empty-text { color: var(--muted); max-width: 420px; margin: 0 0 var(--s-2); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 100; display: flex; flex-direction: column; gap: var(--s-2); max-width: min(420px, calc(100vw - 40px)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--s-3); padding: 12px 14px; border-radius: var(--radius);
  background: #111827; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px;
  border-left: 4px solid var(--ok); animation: toast-in 150ms ease-out; transition: opacity 200ms ease, transform 200ms ease;
}
.toast-ok { border-left-color: var(--ok); } .toast-info { border-left-color: var(--info); }
.toast-warn { border-left-color: var(--accent); } .toast-danger { border-left-color: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(6px); }
.toast-text { flex: 1; }
.toast-close { border: 0; background: none; color: rgba(255,255,255,.6); font-size: 18px; line-height: 1; cursor: pointer; padding: 0; }
.toast-close:hover { color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- lists / misc ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.token-row { display: flex; align-items: center; gap: var(--s-2); margin: var(--s-3) 0 var(--s-4); flex-wrap: wrap; }
.token { display: inline-block; padding: 8px 12px; background: var(--bg); border-radius: var(--radius-sm); word-break: break-all; }
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--s-3); padding: var(--s-4); }
.pagination-info { color: var(--muted); font-size: 12.5px; }

/* dashboard modules */
.module-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); }
.module-card { display: flex; align-items: center; gap: var(--s-3); color: var(--text); padding: var(--s-4); transition: box-shadow var(--t), transform var(--t), border-color var(--t); }
.module-card:hover { color: var(--text); border-color: #c7d2fe00; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.module-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--primary-50); color: var(--primary); flex: none; }
.module-body { flex: 1; min-width: 0; }
.module-title { font-weight: 600; }
.module-sub { font-size: 12.5px; }
@media (max-width: 1100px) { .module-grid { grid-template-columns: repeat(2, 1fr); } }

/* auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s-6); }
.auth-card { width: 100%; max-width: 400px; padding: var(--s-8); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: var(--s-6); }
.auth-title { font-size: 20px; margin-bottom: var(--s-1); }
.auth-card .muted { margin-bottom: var(--s-5); }

/* error pages */
.error-page { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 64px var(--s-4); gap: var(--s-2); }
.error-code { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; color: var(--border); line-height: 1; }
.error-icon { color: var(--primary); }
.error-title { font-size: 20px; }
.error-text { color: var(--muted); max-width: 420px; }
.error-actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); }

/* ---------- bottom nav (mobile) ---------- */
.bottomnav { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); width: var(--sidebar-w) !important; box-shadow: none; }
  html.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  html.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 35; }
  html.sidebar-collapsed .nav-label, html.sidebar-collapsed .brand-name { display: inline; }
  html.sidebar-collapsed .nav-item { justify-content: flex-start; padding: 8px 10px; }
  html.sidebar-collapsed .sidebar-brand { justify-content: space-between; padding: 0 var(--s-4); }
  .sidebar-close { display: inline-grid; }
  .sidebar-footer { display: none; }
  .topbar { padding: 0 var(--s-4); }
  .topbar-menu { display: inline-grid; }
  .content { padding: var(--s-4) var(--s-4) calc(64px + env(safe-area-inset-bottom)); }
  .bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px;
    color: var(--muted); font-size: 10.5px; font-weight: 500; border: 0; background: none; font-family: inherit; cursor: pointer;
  }
  .bottomnav-item.active { color: var(--primary); }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-actions { width: 100%; }
  .kpi-grid, .module-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .toasts { left: var(--s-4); right: var(--s-4); bottom: calc(64px + env(safe-area-inset-bottom)); max-width: none; }
}
@media (max-width: 520px) { .kpi-grid, .module-grid { grid-template-columns: 1fr; } .topbar-tenant { display: none; } }

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .bottomnav, .toasts, .page-actions, .btn, .tabs-nav { display: none !important; }
  body { background: #fff; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
  .table-wrap { max-height: none; overflow: visible; }
  .table thead th { position: static; }
  a { color: inherit; }
}

/* ---------- upozorňovací pruh (odhad DPH, nesoulad plánu se smlouvou) ---------- */
.notice {
  display: block; padding: 10px 12px; margin-bottom: var(--s-4);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 12.5px; line-height: 1.5;
}
.notice + .notice { margin-top: calc(-1 * var(--s-2)); }
.notice-warn { border-color: #fde68a; background: var(--warn-50); color: #92400e; }
.notice-danger { border-color: #fecaca; background: var(--danger-50); color: var(--danger); }
.notice a { text-decoration: underline; }
