:root {
  --ink: #282b25;
  --muted: #74766e;
  --bg: #f3f0e9;
  --card: #fffefb;
  --line: #ddd8cc;
  --brand: #6f795f;
  --brand-dark: #525d48;
  --brand2: #e8ebdf;
  --accent: #b18a69;
  --accent-soft: #efe3d7;
  --danger: #9a4f49;
  --sidebar: #394139;
  --sidebar-ink: #f7f4ec;
  --shadow: 0 14px 38px rgba(54, 55, 46, .07);
  --shadow-soft: 0 5px 18px rgba(54, 55, 46, .05);
  --radius: 8px;
  --radius-lg: 14px;
  font-family: "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button, input, select, textarea { color: var(--ink); }
:focus-visible { outline: 3px solid rgba(177, 138, 105, .38); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 32px 20px;
  overflow: hidden; background: var(--sidebar); color: var(--sidebar-ink);
}
.sidebar::before, .sidebar::after {
  content: ""; position: absolute; pointer-events: none; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .09);
}
.sidebar::before { width: 230px; height: 230px; right: -128px; top: -92px; }
.sidebar::after { width: 170px; height: 170px; left: -115px; bottom: 110px; }
.brand { position: relative; z-index: 1; display: flex; gap: 13px; align-items: center; padding: 0 10px 40px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.42);
  border-radius: 50%; color: var(--sidebar-ink); font-family: Georgia, "Times New Roman", serif; font-size: 20px;
}
.brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 19px; font-weight: 500; letter-spacing: .02em; }
.brand small { display: block; opacity: .66; margin-top: 4px; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.nav { position: relative; z-index: 1; display: grid; gap: 5px; }
.nav button {
  display: flex; align-items: center; gap: 12px; min-height: 46px; border: 0; border-radius: var(--radius);
  padding: 11px 13px; color: rgba(247,244,236,.78); background: transparent; text-align: left;
  transition: color .18s ease, background .18s ease, transform .18s ease;
}
.nav button:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(2px); }
.nav button.active { color: var(--ink); background: #f4f0e8; box-shadow: 0 7px 18px rgba(20,25,20,.13); }
.nav span { width: 24px; text-align: center; font-size: 17px; font-weight: 400; }
.nav b { font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.profile { position: absolute; z-index: 1; bottom: 26px; left: 20px; right: 20px; border-top: 1px solid rgba(255,255,255,.14); padding: 20px 10px 0; font-size: 12px; }
.profile strong { font-family: Georgia, "Times New Roman", serif; font-size: 14px; font-weight: 500; }

.main { min-width: 0; position: relative; }
.main::before {
  content: ""; position: fixed; pointer-events: none; width: 420px; height: 420px; right: -210px; top: 120px;
  border-radius: 50%; background: rgba(219, 214, 199, .2); z-index: -1;
}
.topbar {
  height: 78px; padding: 0 40px; display: flex; align-items: center; justify-content: space-between; gap: 18px;
  border-bottom: 1px solid rgba(201,195,181,.72); background: rgba(247,245,239,.88); backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 5;
}
.search { width: min(450px, 48vw); border: 0; border-bottom: 1px solid #bdb7aa; background: transparent; border-radius: 0; padding: 11px 4px; }
.search::placeholder { color: #8b8a83; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-logout { border: 0; background: transparent; color: var(--brand-dark); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.content { padding: 40px 42px 70px; max-width: 1460px; margin: auto; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 30px; }
.inline-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.title-row h1 { margin: 0 0 8px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(29px, 3vw, 40px); font-weight: 400; line-height: 1.08; letter-spacing: -.018em; }
.subtle { color: var(--muted); font-size: 13px; }

.btn {
  min-height: 42px; border: 1px solid #bdb7aa; border-radius: 2px; padding: 10px 17px; background: transparent; color: var(--ink);
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.btn:hover { background: #ebe6dc; border-color: #9f998c; }
.btn.primary { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }
.btn.primary:hover { background: #424b3b; transform: translateY(-1px); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 11px; }

.grid { display: grid; gap: 20px; }
.stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; }
.card { background: rgba(255,254,251,.93); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow-soft); }
.stat { position: relative; overflow: hidden; min-height: 148px; }
.stat::after { content: ""; position: absolute; width: 64px; height: 64px; right: -28px; top: -28px; border: 1px solid #d7d2c6; border-radius: 50%; }
.stat strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 38px; font-weight: 400; margin: 13px 0 7px; }
.two { grid-template-columns: 1.45fr 1fr; }
.card h2 { font-family: Georgia, "Times New Roman", serif; font-size: 20px; font-weight: 400; margin: 0 0 18px; }
.list { display: grid; gap: 9px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px; border: 1px solid transparent; border-bottom-color: var(--line); border-radius: 0; background: transparent; transition: background .16s ease, border-color .16s ease; }
.row:last-child { border-bottom-color: transparent; }
.row:hover { background: #f7f4ed; border-color: #e0dbcf; border-radius: var(--radius); }
.row-action { border: 0; padding: 7px 4px; background: transparent; color: var(--brand-dark); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.avatar { display: grid; place-items: center; flex: 0 0 40px; height: 40px; border-radius: 50%; background: var(--brand2); color: var(--brand-dark); font-family: Georgia, "Times New Roman", serif; font-weight: 600; }
.grow { flex: 1; min-width: 0; }
.grow strong, .grow small { display: block; }
.grow strong { font-size: 14px; }
.grow small { color: var(--muted); margin-top: 4px; font-size: 12px; }
.pill { display: inline-block; border-radius: 999px; padding: 5px 10px; background: var(--brand2); color: var(--brand-dark); font-size: 10px; font-weight: 700; letter-spacing: .055em; text-transform: uppercase; }
.pill.orange { background: var(--accent-soft); color: #795b43; }
.pill.gray { background: #efeee9; color: #666861; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 15px 11px; border-bottom: 1px solid var(--line); font-size: 13px; }
.table th { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.table tr[data-id] { cursor: pointer; }
.table tbody tr { transition: background .16s ease; }
.table tbody tr:hover { background: #f7f4ed; }
.empty { text-align: center; color: var(--muted); padding: 42px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow: auto; }
.tabs button { border: 0; background: none; padding: 11px 14px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
.tabs .active { color: var(--brand-dark); border-bottom: 2px solid var(--brand); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 10px; color: #66685f; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #cbc5b8; border-radius: 3px; padding: 11px 12px; background: #fffefb; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.field textarea { min-height: 110px; resize: vertical; }
.error { font-size: 12px; color: var(--danger); }
.invoice-item { display: grid; grid-template-columns: minmax(0,1fr) 82px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.invoice-item select, .invoice-item input { width: 100%; border: 1px solid #cbc5b8; border-radius: 3px; padding: 10px; background: #fffefb; }

dialog { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(640px, calc(100vw - 30px)); background: var(--card); box-shadow: 0 32px 100px rgba(31,34,28,.28); }
dialog::backdrop { background: rgba(38, 42, 35, .5); backdrop-filter: blur(3px); }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 400; }
.modal-body { padding: 24px; }
.modal-foot { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; gap: 10px; }

.calendar { display: grid; grid-template-columns: 78px repeat(var(--cal-days, 7), minmax(145px, 1fr)); min-width: 1100px; }
.cal-head, .cal-time, .cal-cell { padding: 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 60px; }
.cal-head { background: #f1eee7; font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
.cal-time { font-size: 11px; color: var(--muted); }
.event { padding: 8px; border-left: 3px solid var(--brand); border-radius: 2px; background: var(--brand2); color: var(--brand-dark); font-size: 11px; }
.event.done { border-color: #a5a79f; background: #efeee9; color: #666861; }
.scroll { overflow: auto; }
.note { border-left: 2px solid var(--accent); padding: 12px 16px; background: #f8f5ef; border-radius: 0 5px 5px 0; }
.signature { border: 1px dashed #aaa697; border-radius: 4px; background: #fffefb; width: 100%; height: 160px; touch-action: none; }
.signature-preview { display: grid; place-items: center; min-height: 180px; padding: 18px; border: 1px solid var(--line); border-radius: 4px; background: #fffefb; }
.signature-preview img { display: block; max-width: 100%; max-height: 260px; object-fit: contain; }
.invoice-document { color: #252821; }
.invoice-kicker { margin-bottom: 22px; color: var(--brand-dark); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.invoice-heading { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 28px; }
.invoice-heading h2 { margin: 0; font-size: 28px; }
.invoice-heading p { margin: 5px 0 0; color: var(--muted); white-space: pre-line; }
.invoice-document table { width: 100%; border-collapse: collapse; }
.invoice-document th, .invoice-document td { padding: 11px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.invoice-document th:first-child, .invoice-document td:first-child { text-align: left; }
.invoice-document tfoot td { padding-top: 16px; border-bottom: 0; font-weight: 700; }
.invoice-warning { margin: 26px 0 0; padding: 12px; background: var(--accent-soft); color: #695441; font-size: 11px; line-height: 1.5; }
.notice { padding: 14px 16px; border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0; background: #f5ece3; color: #695441; font-size: 12px; margin-bottom: 18px; }
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--sidebar); color: #fff; padding: 13px 18px; border-radius: 4px; box-shadow: var(--shadow); z-index: 20; font-size: 13px; }
.checkbox { width: 20px; height: 20px; accent-color: var(--brand); }
.task-done { text-decoration: line-through; color: var(--muted); }
.profile-logout { display: block; border: 0; padding: 8px 0 0; background: transparent; color: rgba(255,255,255,.72); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 14px; padding: 24px; background: radial-gradient(circle at 82% 18%, rgba(111,121,95,.11), transparent 34%), var(--bg); }
.auth-card { width: min(460px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--card); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 34px; }
.auth-brand .brand-mark, .loading-mark { border-color: var(--brand); color: var(--brand-dark); }
.auth-brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 19px; font-weight: 500; }
.auth-brand small { color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.auth-card h1 { margin: 0 0 9px; font-family: Georgia, "Times New Roman", serif; font-size: 36px; font-weight: 400; }
.auth-card > p { color: var(--muted); margin: 0 0 25px; }
.auth-card form { display: grid; gap: 17px; }
.auth-card form .btn { margin-top: 5px; }
.auth-error, .modal-error { min-height: 18px; color: var(--danger); font-size: 12px; margin-top: 10px; }
.auth-hint { display: block; margin-top: 24px; color: var(--muted); line-height: 1.5; }
.loading-mark { display: grid; place-items: center; width: 54px; height: 54px; border: 1px solid; border-radius: 50%; font-family: Georgia, "Times New Roman", serif; font-size: 24px; }
.btn:disabled { opacity: .55; cursor: wait; transform: none !important; }

@media (max-width: 1000px) {
  .shell { grid-template-columns: 78px minmax(0, 1fr); }
  .sidebar { padding: 25px 11px; }
  .brand strong, .brand small, .nav button b, .profile { display: none; }
  .brand { padding: 0 7px 30px; }
  .nav button { justify-content: center; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .two { grid-template-columns: 1fr; }
  .content { padding-left: 30px; padding-right: 30px; }
}

@media (max-width: 650px) {
  .shell { display: block; }
  .sidebar { height: auto; position: fixed; z-index: 10; bottom: 0; top: auto; left: 0; right: 0; padding: 7px 9px; }
  .sidebar::before, .sidebar::after, .brand, .profile { display: none; }
  .nav { display: flex; justify-content: space-around; }
  .nav button { min-height: 48px; padding: 9px 8px; }
  .nav button:hover { transform: none; }
  .nav button b { display: none; }
  .nav span { font-size: 18px; }
  .topbar { height: 62px; padding: 0 16px; }
  .content { padding: 28px 16px 92px; }
  .search { width: 58vw; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat { min-height: 132px; }
  .stat strong { font-size: 31px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .invoice-item { grid-template-columns: 1fr 70px; }
  .invoice-item .remove-item { grid-column: 1 / -1; justify-self: end; }
  .title-row { align-items: center; }
  .title-row h1 { font-size: 27px; }
  .card { padding: 16px; }
  .hide-mobile { display: none; }
  .btn { padding-left: 12px; padding-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
  body * { visibility: hidden !important; }
  dialog.invoice-print[open], dialog.invoice-print[open] * { visibility: visible !important; }
  dialog.invoice-print[open] { position: absolute; inset: 0; width: 100%; max-width: none; min-height: 100%; margin: 0; border-radius: 0; box-shadow: none; }
  dialog.invoice-print .modal-head button, dialog.invoice-print .modal-foot { display: none !important; }
  dialog.invoice-print .modal-body { padding: 18mm; }
  dialog.invoice-print::backdrop { display: none; }
}
