:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --brand: #0e7490; --brand-dark: #155e75; --brand-soft: #ecfeff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --info-soft: #e0f2fe;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
small, .muted { color: var(--muted); }

/* Layout */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 220px; background: #0f2a33; color: #cbd5e1; display: flex; flex-direction: column; padding: 16px 12px; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: #cbd5e1; padding: 8px 10px; border-radius: 8px; }
.sidebar nav a:hover { background: #17404d; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar nav .sep { margin: 12px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; }
.me { border-top: 1px solid #1e4652; padding: 12px 8px 0; font-size: 13px; }
.me strong { color: #fff; display: block; }
.me a, .me button { color: #93c5fd; font-size: 12px; }
.me button { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 12px; }
main { padding: 24px 28px 48px; max-width: 1400px; }
main.with-sidebar { margin-left: 220px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Panels & grids */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.card.alert .value { color: var(--bad); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
@media (max-width: 1000px) { .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr); } }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.clickable:hover td { background: #f8fafc; }

/* Forms */
form.inline { display: inline; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: #374151; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #67e8f9; border-color: var(--brand); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; width: 60px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.search { display: flex; gap: 8px; }
.search input { max-width: 340px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; font-weight: 500; }

/* Badges & flashes */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #f3f4f6; color: #374151; }
.badge.scheduled { background: var(--info-soft); color: #075985; }
.badge.confirmed { background: #ede9fe; color: #5b21b6; }
.badge.arrived { background: var(--warn-soft); color: var(--warn); }
.badge.completed, .badge.paid { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled, .badge.no_show, .badge.unpaid { background: var(--bad-soft); color: var(--bad); }
.badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.low { background: var(--bad-soft); color: var(--bad); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.success { background: var(--ok-soft); border-color: #bbf7d0; color: #14532d; }
.flash.error { background: var(--bad-soft); border-color: #fecaca; color: #7f1d1d; }
.flash.info { background: var(--info-soft); border-color: #bae6fd; color: #0c4a6e; }
.alert-box { background: var(--bad-soft); border: 1px solid #fecaca; color: #7f1d1d; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* Detail lists */
dl.details { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; white-space: pre-wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs a.active { border-color: var(--brand); color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Calendar */
.cal { table-layout: fixed; background: #fff; }
.cal th.time, .cal td.time { width: 64px; color: var(--muted); font-size: 12px; text-align: right; padding-right: 8px; }
.cal td { height: 34px; padding: 2px 4px; border-left: 1px solid var(--line); }
.cal td.slot a { display: block; height: 100%; min-height: 28px; border-radius: 6px; }
.cal td.slot a:hover { background: var(--brand-soft); }
.cal .appt { border-radius: 8px; padding: 6px 8px; font-size: 12px; height: 100%; border-left: 4px solid var(--c, var(--brand)); background: color-mix(in srgb, var(--c, var(--brand)) 12%, white); }
.cal .appt a.name { font-weight: 700; color: var(--ink); }
.cal .appt .meta { color: #4b5563; }
.cal th.prov { border-left: 1px solid var(--line); }
.cal th .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status-form select { width: auto; padding: 2px 6px; font-size: 11px; border-radius: 6px; }

/* Invoice */
.invoice-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.totals { margin-left: auto; width: 320px; }
.totals td { border: 0; padding: 4px 10px; }
.totals tr.grand td { font-weight: 700; font-size: 16px; border-top: 2px solid var(--ink); }
.items-table input { padding: 6px 8px; }
.bar { height: 10px; background: var(--brand); border-radius: 4px; min-width: 2px; }

/* Login */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .panel { padding: 28px; }
.auth h1 { margin-bottom: 6px; }

/* Mobile top bar & slide-out menu (hidden on desktop) */
.topbar, .nav-backdrop, .menu-close { display: none; }
.brand { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }

@media (max-width: 900px) {
  body { font-size: 15px; }
  .topbar { display: flex; align-items: center; gap: 10px; position: fixed; inset: 0 0 auto 0; height: 56px; padding: 0 12px;
            background: #0f2a33; color: #fff; z-index: 40; box-shadow: 0 1px 6px rgba(0,0,0,.2); }
  .topbar-brand { color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-brand:hover { text-decoration: none; }
  .menu-btn, .menu-close { background: none; border: 0; color: #fff; font-size: 24px; line-height: 1; padding: 8px; cursor: pointer; }
  .menu-close { display: block; font-size: 20px; padding: 0 4px; }
  .sidebar { width: 270px; z-index: 60; transform: translateX(-100%); transition: transform .2s ease; overflow-y: auto; }
  body.nav-open .sidebar { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.3); }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
  .sidebar nav a { padding: 11px 12px; font-size: 15px; }

  main, main.with-sidebar { margin-left: 0; padding: 72px 12px 40px; }
  h1 { font-size: 20px; }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; justify-content: center; }
  .search { width: 100%; flex-wrap: wrap; }
  .search input, .search select { max-width: none; flex: 1 1 160px; }

  .panel { padding: 14px; overflow-x: auto; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px; }
  .card .label { font-size: 11px; }
  .card .value { font-size: 19px; overflow-wrap: anywhere; }
  .grid { gap: 12px; }

  th, td { padding: 8px 8px; }
  .panel > table, .table-wrap > table { min-width: 520px; }
  .panel > table.totals { min-width: 0; }
  dl.details { grid-template-columns: 1fr; gap: 0; }
  dl.details dt { font-size: 12px; margin-top: 8px; }
  .tabs { overflow-x: auto; white-space: nowrap; }
  .tabs a { padding: 8px 10px; }

  /* 16px inputs stop iPhone from zooming in when you tap a field */
  input, select, textarea { font-size: 16px; }
  .status-form select { font-size: 13px; }

  /* Calendar: scroll sideways, time column stays visible */
  .cal th.time, .cal td.time { position: sticky; left: 0; background: #fff; z-index: 2; width: 56px; }
  .cal th.prov { font-size: 11px; }

  /* Invoices */
  .invoice-head { flex-direction: column; gap: 8px; }
  .invoice-head > div:last-child { text-align: left !important; }
  .totals { width: 100%; }
  .items-table { min-width: 640px; }
  .form-actions .btn { flex: 1; justify-content: center; }
  .auth { margin: 4vh auto; }

  /* Lists become stacked cards on phones */
  .table-wrap > table.stack { min-width: 0; }
  table.stack tr:first-child { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { display: block; border: 0; padding: 5px 2px; text-align: right; overflow: hidden; }
  table.stack td::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 22px; }
  table.stack td[data-label=""]::before { content: none; }

  /* Invoice line items: one card per line */
  .items-table { min-width: 0 !important; }
  .items-table thead { display: none; }
  .items-table tr.item-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .items-table tr.item-row td { display: block; border: 0; padding: 0; }
  .items-table tr.item-row td:nth-child(1), .items-table tr.item-row td:nth-child(2) { grid-column: 1 / -1; }
  .items-table tr.item-row td::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
  .items-table td.amount { align-self: center; font-weight: 700; text-align: left; }
  .items-table td:last-child { align-self: center; text-align: right; }
}

@media print {
  .no-print, .sidebar, .flash { display: none !important; }
  main.with-sidebar { margin: 0; padding: 0; }
  body { background: #fff; }
  .panel { border: 0; padding: 0; }
}
