:root {
  --primary: #0f6a72;
  --primary-dark: #08363b;
  --primary-soft: #e6f2f3;
  --accent: #d4a24c;
  --bg: #f4f6f9;
  --card: #fff;
  --text: #17222d;
  --muted: #667585;
  --line: #e6eaef;
  --ok: #178a5b;
  --warn: #c77d0a;
  --bad: #c8402f;
  --radius: 14px;
  --sidebar: 262px;
  --shadow: 0 1px 2px rgba(16,34,48,.04), 0 6px 20px -8px rgba(16,34,48,.10);
  --shadow-lg: 0 2px 4px rgba(16,34,48,.05), 0 16px 36px -12px rgba(16,34,48,.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 .85rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.right { text-align: end; }
.nowrap { white-space: nowrap; }

/* Shell */
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0;
  width: var(--sidebar); color: #cfe0e2; padding-bottom: 1.5rem;
  background: radial-gradient(120% 60% at 0% 0%, #0f5a62 0%, transparent 60%), linear-gradient(180deg, #0a4047 0%, var(--primary-dark) 100%);
  overflow-y: auto; z-index: 30; transition: transform .2s;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.25rem 1.1rem 1.1rem; color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand img { max-height: 40px; max-width: 56px; object-fit: contain; background: #fff; border-radius: 10px; padding: 3px; }
.nav-group { padding: 1rem 1.1rem .35rem; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: #7fa6aa; }
summary.nav-group { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; user-select: none; transition: color .15s; }
summary.nav-group::-webkit-details-marker { display: none; }
summary.nav-group::after { content: ''; width: .38rem; height: .38rem; border-inline-end: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .18s; margin-top: -.15rem; }
details.nav-section[open] > summary.nav-group::after { transform: rotate(-135deg); margin-top: .15rem; }
summary.nav-group:hover { color: #fff; }
.sidebar a.nav { display: flex; align-items: center; gap: .7rem; margin: 2px .65rem; padding: .5rem .7rem; color: #cfe0e2; border-radius: 10px; transition: background .15s, color .15s; }
.sidebar a.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
.sidebar a.nav:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar a.nav:hover svg { opacity: 1; }
.sidebar a.nav.active { background: linear-gradient(90deg, rgba(212,162,76,.95), rgba(212,162,76,.78)); color: #2b1d04; font-weight: 650; box-shadow: 0 6px 16px -6px rgba(212,162,76,.6); }
.sidebar a.nav.active svg { opacity: 1; }

.main { margin-inline-start: var(--sidebar); min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem; background: rgba(255,255,255,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.topbar > strong { font-size: 1rem; font-weight: 650; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--text); }
.content { padding: 1.6rem 1.75rem 2.5rem; max-width: 1440px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.page-head .spacer { flex: 1; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1.1rem; }
.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 { --tone: var(--primary); position: relative; overflow: hidden; display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.stat::before { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--tone); }
.stat::after { content: ''; position: absolute; inset-inline-end: -28px; top: -28px; width: 96px; height: 96px; border-radius: 50%; background: var(--tone); opacity: .08; }
a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); text-decoration: none; }
.stat .n { font-size: 1.75rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .84rem; margin-top: .2rem; }
.stat.warn { --tone: var(--warn); }
.stat.bad { --tone: var(--bad); }
.stat.ok { --tone: var(--ok); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: #f8fafb; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #f9fbfc; }
tfoot td { font-weight: 700; background: #f8fafb; }

/* Forms & buttons */
label { display: block; font-size: .82rem; font-weight: 650; color: #33414e; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=file], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid #d5dce3; border-radius: 10px; font: inherit; background: #fff; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #b9c4cd; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15,106,114,.14); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: auto; accent-color: var(--primary); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1.1rem; border-radius: 10px; border: 1px solid transparent; background: linear-gradient(180deg, #137c85, var(--primary)); color: #fff; cursor: pointer; font: inherit; font-weight: 650; line-height: 1.2; box-shadow: 0 4px 12px -4px rgba(15,106,114,.55); transition: transform .12s, box-shadow .15s, background .15s; }
.btn:hover { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); text-decoration: none; transform: translateY(-1px); box-shadow: 0 8px 16px -6px rgba(15,106,114,.6); }
.btn:active { transform: none; }
.btn.secondary { background: #fff; color: var(--primary); border-color: #cfe0e2; box-shadow: none; }
.btn.secondary:hover { background: var(--primary-soft); border-color: var(--primary); box-shadow: none; }
.btn.danger { background: #fff; color: var(--bad); border-color: #efc4be; box-shadow: none; }
.btn.danger:hover { background: #fdf0ee; border-color: var(--bad); box-shadow: none; }
.btn.small { padding: .3rem .7rem; font-size: .82rem; border-radius: 8px; }
.inline-form { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1.1rem; padding: .7rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters input, .filters select { width: auto; min-width: 150px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
/* A table cell must stay a table cell, otherwise the row border breaks under the buttons. */
td.actions { display: table-cell; white-space: nowrap; }
td.actions > * { margin-inline-end: .35rem; vertical-align: middle; }

/* Badges & alerts */
.badge { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .74rem; font-weight: 650; background: #e8edf1; color: #44525f; }
.badge.ok { background: #dff3e9; color: #11633f; }
.badge.warn { background: #fdf0d5; color: #8a5600; }
.badge.bad { background: #fbe1dd; color: #902a1d; }
.badge.info { background: #dcecf7; color: #1b5a86; }
.flash { padding: .8rem 1.1rem; border-radius: 12px; margin-bottom: 1.1rem; border: 1px solid transparent; box-shadow: var(--shadow); }
.flash.ok { border-color: #bfe5d1; }
.flash.bad { border-color: #f1c3bc; }
.flash.ok { background: #dff3e9; color: #11633f; }
.flash.bad { background: #fbe1dd; color: #902a1d; }
.flash ul { margin: 0; padding-inline-start: 1.1rem; }

/* Pagination */
.pager { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: 1rem; }
.pager a, .pager span { padding: .35rem .75rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pager .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; position: relative; overflow: hidden;
  background: radial-gradient(60% 80% at 15% 10%, #14808a 0%, transparent 60%), radial-gradient(50% 60% at 90% 90%, rgba(212,162,76,.35) 0%, transparent 60%), linear-gradient(135deg, var(--primary-dark), #0d5961); }
.auth::before, .auth::after { content: ''; position: absolute; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); pointer-events: none; }
.auth::before { width: 520px; height: 520px; inset-inline-start: -160px; bottom: -220px; }
.auth::after { width: 340px; height: 340px; inset-inline-end: -90px; top: -110px; }
.auth .box { position: relative; z-index: 1; width: 100%; max-width: 400px; background: rgba(255,255,255,.97); border-radius: 22px; padding: 2.4rem 2.2rem 1.8rem; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); }
.auth .box .btn { padding: .75rem 1rem; font-size: 1rem; }
.auth .logo { text-align: center; margin-bottom: 1.5rem; }
.auth .logo img { max-height: 80px; max-width: 200px; }
.auth .logo h1 { font-size: 1.5rem; margin: .6rem 0 .15rem; }
.auth .logo .mark { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; color: #2b1d04; background: linear-gradient(135deg, #e6b95f, var(--accent)); box-shadow: 0 10px 20px -8px rgba(212,162,76,.8); }
.auth .logo .mark svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Printable documents */
.doc { max-width: 820px; margin: 1rem auto; background: #fff; padding: 2rem 2.2rem; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid var(--primary); padding-bottom: 1rem; margin-bottom: 1.25rem; }
.doc-head img { max-height: 70px; max-width: 200px; }
.doc h1.title { text-align: end; color: var(--primary); letter-spacing: .05em; text-transform: uppercase; }
.doc table th { background: var(--primary); color: #fff; }
.doc .totals { margin-inline-start: auto; width: 320px; margin-top: 1rem; }
.doc .totals td { border: 0; padding: .25rem .5rem; }
.doc .totals tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--primary); }
.doc-foot { margin-top: 2rem; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: .75rem; }
.toolbar { max-width: 820px; margin: 1rem auto 0; display: flex; gap: .5rem; }

/* Profile pictures */
.avatar { border-radius: 50%; object-fit: cover; flex: none; display: inline-block; vertical-align: middle; }
.avatar-initials { background: linear-gradient(135deg, #14808a, var(--primary-dark)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.topuser { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); }
.topuser:hover { text-decoration: none; }
@media (max-width: 600px) { .topuser span:last-child { display: none; } }

/* Mode banners (View as / test database) */
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .45rem 1.25rem; font-size: .88rem; position: sticky; top: 0; z-index: 25; }
.banner-view { background: #1f4e79; color: #fff; }
.banner-test { background: #c0392b; color: #fff; }
.banner .btn { background: #fff; color: #1f2933; border-color: #fff; }
.banner + .topbar, .banner + .banner + .topbar { top: auto; }

/* Guides */
.guide-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 1.25rem; align-items: start; }
.guide-toc { position: sticky; top: 4.5rem; font-size: .9rem; }
.guide-toc a { display: block; padding: .3rem .6rem; border-radius: 8px; color: var(--muted); }
.guide-toc a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.guide section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.35rem; margin-bottom: 1rem; scroll-margin-top: 4.5rem; }
.guide h2 { margin-bottom: .5rem; }
.guide h3 { margin: 1rem 0 .25rem; }
.guide ul, .guide ol { padding-inline-start: 1.3rem; margin: .4rem 0; }
.guide li { margin: .2rem 0; }
.guide .tip { background: var(--primary-soft); border-inline-start: 4px solid var(--primary); padding: .5rem .8rem; border-radius: 6px; margin: .6rem 0; }
.guide .warn { background: #fdf0d5; border-inline-start: 4px solid var(--warn); padding: .5rem .8rem; border-radius: 6px; margin: .6rem 0; }
.guide kbd, .guide code { background: #eef1f4; padding: .05rem .35rem; border-radius: 4px; font-size: .88em; }
@media (max-width: 900px) { .guide-wrap { grid-template-columns: 1fr; } .guide-toc { position: static; } }

@media print {
  .guide-toc { display: none; }
  .guide-wrap { display: block; }
  .guide section { break-inside: avoid; }
  .sidebar, .topbar, .no-print, .toolbar, .flash { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .doc { border: 0; margin: 0; padding: 0; max-width: none; }
  .card { break-inside: avoid; }
}

@media (max-width: 900px) {
  .topbar { padding: .6rem 1rem; }
  .sidebar { transform: translateX(-100%); }
  [dir=rtl] .sidebar { transform: translateX(100%); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.4); }
  .main { margin-inline-start: 0; }
  .menu-btn { display: block; }
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .content { padding: .9rem; }
}
@media (max-width: 600px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .doc { padding: 1rem; }
  .doc-head { flex-direction: column; }
  .doc h1.title { text-align: start; }
}
