:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #d3dae6;
  --ink: #14213a;
  --muted: #647089;
  --muted-2: #8b97ad;
  --primary: #2f6df6;
  --primary-dark: #1f55cf;
  --primary-soft: #eaf1ff;
  --success: #15a06b;
  --success-soft: #e3f7ee;
  --warning: #c4820a;
  --warning-soft: #fdf3df;
  --danger: #d6453d;
  --danger-soft: #fdeceb;
  --shadow: 0 18px 40px -24px rgba(20, 33, 58, 0.45);
  --shadow-sm: 0 8px 22px -16px rgba(20, 33, 58, 0.5);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: 'Manrope', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e7eefc 0%, var(--bg) 55%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card .brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--primary), #5b8cff);
  color: #fff;
  font-size: 26px;
  font-weight: 800;
}
.auth-card h1 { font-size: 22px; }
.auth-card .sub { color: var(--muted); margin: 6px 0 24px; font-size: 14px; }
.auth-card form { text-align: left; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #0f1b32;
  color: #cdd7ea;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 22px;
  color: #fff;
}
.sidebar .brand .logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #5b8cff);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
}
.sidebar .brand b { font-size: 17px; font-weight: 800; letter-spacing: 0.2px; }
.sidebar .brand span { display: block; font-size: 11px; color: #8595b5; font-weight: 600; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 11px;
  color: #aeb9d2;
  font-weight: 600;
  font-size: 14.5px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .ico { width: 20px; text-align: center; font-size: 16px; }
.sidebar .spacer { flex: 1; }
.sidebar .logout {
  color: #93a1c0;
  justify-content: flex-start;
}
.sidebar .logout:hover { color: #fff; background: rgba(255,255,255,0.06); }
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; margin-bottom: 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user .su-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  background: rgba(255,255,255,0.12); color: #fff;
}
.sidebar-user .su-meta { min-width: 0; line-height: 1.25; }
.sidebar-user .su-meta b { color: #fff; font-size: 13.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .su-meta span { color: #8595b5; font-size: 11px; font-weight: 600; }
.owner-line {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 6px 10px; background: var(--surface-2); border-radius: 8px;
}
.owner-line .muted { font-weight: 500; }

.main {
  padding: 28px 34px 60px;
  max-width: 1180px;
  width: 100%;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 25px; }
.page-head .lead { color: var(--muted); margin-top: 6px; font-size: 14.5px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--ink);
  transition: transform 0.06s, background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.subtle { background: var(--surface); border-color: var(--border); color: var(--muted); }
.btn.subtle:hover { color: var(--ink); border-color: var(--border-strong); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: #f9dad8; }
.btn.success { background: var(--success); color: #fff; }
.btn.small { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.pad { padding: 22px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .value { font-size: 27px; font-weight: 800; margin-top: 8px; }
.stat .hint { color: var(--muted-2); font-size: 12.5px; margin-top: 4px; }

/* ---------- Tile lists ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tile .tile-top { display: flex; align-items: center; gap: 12px; }
.tile .tile-logo {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
  background: var(--primary); flex-shrink: 0; overflow: hidden;
}
.tile .tile-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.tile h3 { font-size: 16px; }
.tile .meta { color: var(--muted); font-size: 13px; line-height: 1.5; }
.tile .meta .row { display: flex; gap: 6px; }
.tile .tile-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td { padding: 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  text-transform: capitalize;
}
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-draft { background: var(--surface-2); color: var(--muted); }
.status-sent { background: var(--warning-soft); color: var(--warning); }
.status-paid { background: var(--success-soft); color: var(--success); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--ink); }
.field .help { font-size: 12px; color: var(--muted-2); margin-top: 5px; }
.field.error input, .field.error textarea, .field.error select { border-color: var(--danger); }
.field .error-text { color: var(--danger); font-size: 12px; margin-top: 5px; display: none; }
.field.error .error-text { display: block; }
input, textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.15);
}
textarea { resize: vertical; min-height: 84px; }
input[type="color"] { padding: 4px; height: 44px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section-title {
  font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin: 8px 0 14px; padding-top: 16px; border-top: 1px solid var(--border);
}
.form-section-title.first { border-top: none; padding-top: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17, 26, 46, 0.5);
  display: grid; place-items: center; padding: 20px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px -30px rgba(15, 23, 42, 0.6);
}
.modal.wide { max-width: 920px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 19px; }
.modal-head .close { background: var(--surface-2); border: none; width: 34px; height: 34px; border-radius: 9px; font-size: 18px; color: var(--muted); }
.modal-head .close:hover { background: var(--border); color: var(--ink); }
.modal-body { padding: 22px 24px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2);
}

/* ---------- Invoice composer ---------- */
.composer { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 22px; align-items: start; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 8px; }
.items-table td { padding: 4px 6px; vertical-align: top; }
.items-table input { padding: 9px 10px; }
.items-table .col-qty { width: 72px; }
.items-table .col-price { width: 104px; }
.items-table .col-vat { width: 72px; }
.items-table .col-total { width: 100px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; padding-top: 18px; }
.items-table .col-del { width: 38px; }
.icon-btn {
  border: none; background: var(--surface-2); width: 34px; height: 38px; border-radius: 9px;
  color: var(--muted); font-size: 15px;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

.totals-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.totals-box .line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; color: var(--muted); }
.totals-box .line.grand { border-top: 1px solid var(--border-strong); margin-top: 6px; padding-top: 14px; font-size: 19px; font-weight: 800; color: var(--ink); }
.totals-box .line .v { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

.preview-pane { position: sticky; top: 24px; }
.invoice-preview {
  background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 26px;
  box-shadow: var(--shadow); font-size: 13px; color: #1f2a44;
}
.invoice-preview .accent-bar { height: 8px; border-radius: 6px; margin-bottom: 18px; }
.invoice-preview .pv-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.invoice-preview .pv-logo { max-height: 46px; max-width: 150px; object-fit: contain; margin-bottom: 8px; display: block; }
.invoice-preview h2 { font-size: 19px; }
.invoice-preview .pv-muted { color: var(--muted); font-size: 12px; line-height: 1.55; }
.invoice-preview .pv-doc { text-align: right; }
.invoice-preview .pv-doc .big { font-size: 22px; font-weight: 800; }
.invoice-preview .pv-bill { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.invoice-preview .pv-bill .lbl { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.invoice-preview table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.invoice-preview table th { font-size: 10px; text-transform: uppercase; color: #fff; padding: 7px 8px; text-align: left; }
.invoice-preview table td { padding: 7px 8px; border-bottom: 1px solid var(--border); font-size: 12px; }
.invoice-preview .pv-total { display: flex; justify-content: flex-end; }
.invoice-preview .pv-total .box { width: 220px; }
.invoice-preview .pv-total .line { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; color: var(--muted); }
.invoice-preview .pv-total .grand { color: #fff; padding: 9px 12px; border-radius: 8px; font-weight: 800; font-size: 15px; margin-top: 6px; }
.num-r { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Misc ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.toolbar .search input { padding-left: 36px; }
.toolbar .search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 8px 14px; border-radius: 8px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--primary); color: #fff; }

.empty-state { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-state .emoji { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; color: var(--ink); margin-bottom: 6px; }
.empty-state p { max-width: 360px; margin: 0 auto 18px; font-size: 14px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite; margin: 60px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
  background: #14213a; color: #fff; padding: 13px 18px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14px; font-weight: 600; min-width: 240px; max-width: 360px;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.2s ease;
}
.toast.success { background: #11633f; }
.toast.error { background: #9a2c26; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 980px) {
  .composer { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    overflow-x: auto; padding: 12px; gap: 4px;
  }
  .sidebar .brand { padding: 4px 10px 4px 4px; }
  .sidebar .brand span { display: none; }
  .sidebar .spacer { flex: 0; }
  .sidebar-user { display: none; }
  .nav-link { width: auto; padding: 9px 12px; }
  .nav-link span.txt { display: none; }
  .nav-link .ico { font-size: 18px; }
  .main { padding: 20px 16px 50px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid.cols-3, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
}
