/* The old app's "Slate Precision" MudBlazor theme, rebuilt as plain CSS. */
:root {
  --primary: #334155;
  --primary-dark: #1e293b;
  --primary-light: #475569;
  --amber: #f59e0b;
  --sky: #0ea5e9;
  --info: #3b82f6;
  --success: #10b981;
  --success-dark: #059669;
  --warning: #f59e0b;
  --error: #ef4444;
  --error-dark: #dc2626;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: rgba(15, 23, 42, 0.9);
  --muted: rgba(100, 116, 139, 0.95);
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(100, 116, 139, 0.4);
  --hover: rgba(241, 245, 249, 0.9);
  --appbar: 64px;
  --drawer: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Roboto', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 400; }
.material-icons { font-size: 24px; line-height: 1; vertical-align: middle; user-select: none; }

/* App bar and drawer */
.appbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1200;
  display: flex; align-items: center; gap: 8px;
  height: var(--appbar); padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--primary); color: #fff;
}
.appbar-title { font-size: 20px; font-weight: 500; letter-spacing: 0.0075em; }
.spacer { flex: 1; }
.appbar .icon-btn { color: #fff; }
.appbar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.drawer {
  position: fixed; top: var(--appbar); bottom: 0; left: 0; z-index: 1100;
  width: var(--drawer); overflow-y: auto; padding: 8px 0;
  background: var(--surface); border-right: 1px solid var(--line);
  transition: transform 0.2s ease;
}
.drawer a {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; min-height: 40px;
  color: rgba(30, 41, 59, 0.87); text-decoration: none; font-size: 14px;
}
.drawer a .material-icons { color: rgba(100, 116, 139, 0.87); }
.drawer a:hover { background: var(--hover); }
.drawer a.active { background: rgba(51, 65, 85, 0.08); color: var(--primary); font-weight: 600; }
.drawer a.active .material-icons { color: var(--primary); }

.main {
  margin-top: var(--appbar); margin-left: var(--drawer);
  padding: 16px; transition: margin-left 0.2s ease; min-height: calc(100vh - var(--appbar));
}
body.drawer-closed .drawer { transform: translateX(-100%); }
body.drawer-closed .main { margin-left: 0; }
.container { max-width: 1280px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 24px; }

/* Mobile bottom navigation */
.bottom-nav {
  display: none; position: fixed; inset: auto 0 0 0; z-index: 1100;
  height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid rgba(0, 0, 0, 0.12); box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}
.bottom-nav a {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: rgba(0, 0, 0, 0.6); -webkit-tap-highlight-color: transparent;
}
.bottom-nav span:last-child { font-size: 12px; line-height: 1; margin-top: 2px; }
.bottom-nav a.active { color: var(--primary); font-weight: 600; }
.bottom-nav a.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 32px; height: 3px; background: var(--primary); border-radius: 0 0 3px 3px;
}

/* Text */
.page-title { font-size: 34px; line-height: 1.2; font-weight: 400; }
.section-title { font-size: 20px; font-weight: 500; margin-bottom: 12px; }
.section-title.brand, .brand { color: var(--primary); }
.muted { color: var(--muted); }
.body2 { font-size: 14px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.strong { font-weight: 600; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 16px; }
.card + .card { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.nav-card {
  display: block; padding: 24px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px; transition: background-color 0.2s ease;
}
.nav-card:hover { background: rgba(0, 0, 0, 0.02); }
.nav-card .material-icons { font-size: 36px; color: rgba(100, 116, 139, 0.9); margin-bottom: 12px; display: block; }
.nav-card h2 { font-size: 20px; font-weight: 500; margin-bottom: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 6px 16px; border: 1px solid transparent; border-radius: 4px;
  font: inherit; font-weight: 500; font-size: 14px; letter-spacing: 0.02em; text-transform: uppercase; text-decoration: none;
  cursor: pointer; background: transparent; color: var(--primary); transition: background-color 0.15s ease;
}
.btn:hover { background: rgba(51, 65, 85, 0.06); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn .material-icons { font-size: 18px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-dark); }
.btn-outlined { border-color: var(--line-strong); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: var(--error-dark); }
.btn-full { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.align-self-start { align-self: flex-start; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: rgba(100, 116, 139, 0.12); }
.icon-btn.primary { color: var(--primary); }
.icon-btn.info { color: var(--info); }
.icon-btn.success { color: var(--success); }
.icon-btn.danger { color: var(--error); }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 500; color: var(--muted); }
.field input:not([type=checkbox]), .field select, .field textarea, .search input {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 4px;
}
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.field input:disabled { background: #f1f5f9; color: var(--muted); }
.field textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.duration { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-error { margin: 0; color: var(--error-dark); }
.search { position: relative; }
.search .material-icons { position: absolute; top: 10px; left: 12px; color: var(--muted); }
.search input { padding-left: 44px; }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap.bare { border: 0; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 10px 8px; text-align: left; border-bottom: 1px solid rgba(226, 232, 240, 0.8); vertical-align: middle; overflow-wrap: anywhere; }
table.data th { font-weight: 500; white-space: nowrap; }
table.data th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 2px; }
table.data th button:focus-visible { outline: 2px solid var(--sky); }
table.data th .material-icons { font-size: 16px; opacity: 0.7; }
table.data tbody tr:hover { background: var(--hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Chips */
.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; white-space: nowrap; background: #e2e8f0; color: #334155; }
.chip.info { background: var(--info); color: #fff; }
.chip.success { background: var(--success-dark); color: #fff; }
.chip.warning { background: var(--warning); color: #1e293b; }
.chip.error { background: var(--error-dark); color: #fff; }

/* Invoice detail */
.inv-head { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.inv-company { font-size: 40px; line-height: 1.15; color: var(--primary); margin-bottom: 8px; }
.inv-label { font-size: 28px; color: var(--primary); }
.inv-number { font-size: 22px; margin-top: 8px; }
.inv-block p { margin: 0; }
.inv-card { border: 2px solid #e0e0e0; border-radius: 8px; padding: 32px; }
.divider { border: 0; border-top: 1px solid rgba(226, 232, 240, 0.9); margin: 16px 0; }
.summary-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
.summary { background: #f5f5f5; border-radius: 4px; padding: 16px; }
.summary-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.summary-due { color: var(--error-dark); font-size: 18px; font-weight: 600; }
.paid-text { color: var(--success-dark); font-weight: 600; }

/* Report totals */
.totals { font-size: 18px; font-weight: 500; }

/* About */
.about { background: var(--surface); border-radius: 4px; padding: 32px; box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1); }
.about h1 { font-size: 40px; text-align: center; }
.about .feature-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.about .feature-list li { display: flex; align-items: center; gap: 12px; }
.about .feature-list .material-icons { color: var(--muted); }
.about-offer { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px; border-radius: 4px; color: #fff; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.about-offer h2 { font-size: 24px; margin-bottom: 8px; color: #fff; }
.about-offer .btn { background: #fff; color: #667eea; font-weight: 700; flex: none; }
.about ul.plain { padding-left: 20px; margin: 0; display: grid; gap: 8px; }

/* Dialogs and snackbars */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 1300; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(15, 23, 42, 0.5);
}
.dialog { width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 4px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3); }
.dialog.small { max-width: 440px; }
.dialog header { padding: 16px 24px; font-size: 20px; font-weight: 500; }
.dialog .dialog-body { padding: 8px 24px 16px; overflow-y: auto; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 16px 16px; }
#snackbars { position: fixed; top: 76px; right: 16px; z-index: 1400; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.snackbar { padding: 12px 16px; border-radius: 4px; color: #fff; background: var(--primary-dark); box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25); }
.snackbar.success { background: var(--success-dark); }
.snackbar.error { background: var(--error-dark); }
.snackbar.warning { background: #b45309; }
.spinner { width: 40px; height: 40px; margin: 20px auto; border: 4px solid rgba(51, 65, 85, 0.2); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sign-in */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 88px 16px 24px; }
.login-card { width: 100%; max-width: 400px; padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 28px; }
.login-card p { margin: 0; }
.login-page .btn-primary { min-height: 44px; }

/* Print page: a clean sheet, no app chrome */
body.print-mode { background: #fff; }
.invoice-print { max-width: 800px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; color: #000; background: #fff; }
.invoice-print .pr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; border-bottom: 2px solid #e0e0e0; padding-bottom: 20px; margin-bottom: 30px; }
.invoice-print h1 { color: #1976d2; margin: 0; font-size: 28px; font-weight: 700; }
.invoice-print h2 { color: #1976d2; margin: 0; font-size: 24px; font-weight: 700; }
.invoice-print h3 { color: #1976d2; margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.invoice-print p { margin: 2px 0; font-size: 12px; }
.invoice-print .pr-tag { color: #666; margin: 5px 0; font-size: 14px; }
.invoice-print .pr-num { font-size: 18px; font-weight: 700; margin: 10px 0; }
.invoice-print .pr-bill { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.invoice-print .pr-name { font-weight: 700; font-size: 14px; margin: 5px 0; }
.invoice-print .pr-notes { margin: 20px 0; }
.invoice-print table { width: 100%; border-collapse: collapse; margin-bottom: 30px; }
.invoice-print th, .invoice-print td { border: 1px solid #ddd; padding: 8px; text-align: left; font-size: 13px; }
.invoice-print th { background: #f5f5f5; }
.invoice-print td.num { text-align: right; white-space: nowrap; }
.invoice-print .pr-summary { display: flex; justify-content: space-between; align-items: center; gap: 24px; background: #f9f9f9; padding: 15px; border: 1px solid #ddd; margin-top: 20px; }
.invoice-print .pr-totals { min-width: 220px; }
.invoice-print .pr-line { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.invoice-print .pr-paid { color: #388e3c; }
.invoice-print .pr-due { padding-top: 8px; border-top: 2px solid #333; color: #c62828; font-size: 16px; font-weight: 700; }
.invoice-print .pr-footer { margin-top: 40px; text-align: center; color: #666; font-size: 10px; }

@media print {
  .appbar, .drawer, .bottom-nav, #snackbars, .no-print, .btn { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  .container { padding: 0; }
  .card, .inv-card { border: 0; box-shadow: none; }
  .invoice-print { padding: 0; max-width: none; }
  tr { page-break-inside: avoid; }
}

/* Under 960px: bottom nav replaces the drawer, as in the old app */
@media (max-width: 959px) {
  :root { --appbar: 56px; }
  .drawer, #menu-toggle { display: none; }
  .main { margin-left: 0; padding: 8px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; }
  .container { padding: 8px; gap: 16px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .page-title { font-size: 24px; }
  .inv-head, .summary-grid { grid-template-columns: 1fr; }
  .inv-card { padding: 16px; }
  .inv-company { font-size: 30px; }
  .inv-head .right { text-align: left; }

  /* Tables become label/value rows */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 8px 12px; border-bottom: 1px solid rgba(226, 232, 240, 0.9); }
  table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 6px 0; border: 0; text-align: right; min-height: 32px; }
  table.stack td::before { content: attr(data-label); flex: none; font-weight: 500; color: var(--muted); text-align: left; }
  table.stack td.actions { justify-content: flex-end; }
  table.stack td.actions::before { content: none; }
  .icon-btn { width: 44px; height: 44px; }
  .btn { min-height: 44px; }
  .btn-mobile-full { width: 100%; }
}

@media (max-width: 599px) {
  .card-grid, .form-grid, .form-grid.thirds, .about .feature-list { grid-template-columns: 1fr; }
  .about { padding: 16px; }
  .about h1 { font-size: 28px; }
  .about-offer { flex-direction: column; align-items: stretch; }
  .dialog header { padding: 16px; }
  .dialog .dialog-body { padding: 8px 16px 16px; }
  .invoice-print .pr-head, .invoice-print .pr-bill, .invoice-print .pr-summary { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
