:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1d2733; --muted: #66707d;
  --accent: #1f4e79; --accent-soft: #e8eff6; --line: #dde2e8;
  --ok: #1d7a46; --warn: #b7791f; --bad: #b3362c;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 215px; background: #16293d; color: #cfd8e3; padding: 14px 0; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand { font-size: 18px; font-weight: 700; color: #fff; padding: 4px 18px 14px; }
.sidebar a { display: block; padding: 9px 18px; color: #cfd8e3; }
.sidebar a:hover { background: #1f3550; text-decoration: none; }
.sidebar a.active { background: #1f4e79; color: #fff; }
.sidebar .firm-switch { padding: 0 14px 14px; }
.sidebar .firm-switch select { width: 100%; padding: 6px; border-radius: 6px; border: 1px solid #2d4258; background: #0f1f30; color: #fff; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid #2d4258; padding-top: 8px; }
.sidebar .linklike { background: none; border: none; color: #8fa3b8; padding: 9px 18px; cursor: pointer; font-size: 14px; }
.sidebar .linklike:hover { color: #fff; }

.content { flex: 1; padding: 26px 32px; max-width: 1200px; }
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 23px; font-weight: 700; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th { text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn { display: inline-block; background: var(--accent); color: #fff; border: none; border-radius: 7px; padding: 8px 14px; font-size: 14px; cursor: pointer; }
.btn:hover { background: #163a5c; text-decoration: none; color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.danger { background: #fbeae8; color: var(--bad); }
button.inline { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13.5px; }
button.inline:hover { text-decoration: underline; }

form.stack label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13.5px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; font-family: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 14px; }
.row > * { flex: 1; min-width: 0; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form > div { display: flex; flex-direction: column; gap: 3px; }
.inline-form label { font-size: 12px; font-weight: 600; color: var(--muted); }
.checkline { display: flex; align-items: center; gap: 7px; margin-top: 12px; }
.checkline input { width: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.open, .badge.sent, .badge.in_progress { background: #e8f0fb; color: var(--accent); }
.badge.pending, .badge.draft { background: #f3f4f6; color: var(--muted); }
.badge.closed, .badge.complete, .badge.paid { background: #e3f3e9; color: var(--ok); }
.badge.high, .badge.void, .badge.overdue { background: #fbeae8; color: var(--bad); }
.badge.deposit { background: #e3f3e9; color: var(--ok); }
.badge.disbursement { background: #fdf1e2; color: var(--warn); }

.muted { color: var(--muted); font-size: 13.5px; }
.error-banner { background: #fbeae8; color: var(--bad); border: 1px solid #f0c8c2; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* calendar */
.cal { table-layout: fixed; }
.cal td { height: 104px; padding: 6px; font-size: 13px; }
.cal .daynum { font-weight: 600; color: var(--muted); }
.cal td.today { background: var(--accent-soft); }
.cal .ev { display: block; background: #e8f0fb; border-radius: 5px; padding: 2px 5px; margin-top: 3px; font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; max-width: 540px; width: 92%; }
dialog::backdrop { background: rgba(20,30,45,.45); }
dialog h2 { margin-top: 0; }

/* auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #16293d; }
.auth-card { background: #fff; border-radius: 14px; padding: 34px; width: 420px; max-width: 94%; }
.auth-card h1 { font-size: 20px; }
.auth-card .brand { font-size: 24px; font-weight: 800; color: var(--accent); margin-bottom: 4px; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 20px; background: #fff; border: 1px solid var(--line); font-size: 13.5px; }
.tabs a.on { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 6px; gap: 2px;
    position: sticky; top: 0; z-index: 50; -webkit-overflow-scrolling: touch; }
  .sidebar a { white-space: nowrap; padding: 8px 11px; border-radius: 7px; font-size: 14px; }
  .sidebar .brand { padding: 0 10px 0 6px; font-size: 16px; border: none !important; margin: 0 !important; }
  .sidebar .firm-switch { padding: 0 6px; }
  .sidebar .firm-switch select { width: auto; max-width: 130px; }
  .sidebar-bottom { margin: 0; border: 0; display: flex; align-items: center; }
  .content { padding: 16px 14px; }
  .row { flex-direction: column; }
  table { display: block; overflow-x: auto; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
