:root {
  --ink: #0E1B3D;        /* sidebar navy, from the logo's night sky */
  --ink-2: #172a5c;
  --royal: #2346C8;      /* primary actions */
  --royal-soft: #EAF0FF;
  --gold: #E2A71E;       /* brand ring, used sparingly */
  --gold-soft: #FFF5DB;
  --paper: #F5F6FA;
  --surface: #FFFFFF;
  --line: #E3E6EF;
  --text: #16203A;
  --muted: #667089;
  --green: #148F5A; --green-soft: #E3F6EC;
  --red: #C8323C;   --red-soft: #FDECEC;
  --amber: #B7791F; --amber-soft: #FFF4DE;
  --radius-lg: 14px; --radius: 10px; --radius-sm: 7px;
  --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--paper); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--royal); text-decoration: none; }
:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; grid-template-columns: 1fr 1fr; }
.login-art { background: radial-gradient(120% 90% at 30% 20%, #23408f 0%, var(--ink) 60%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art .ring { position: absolute; right: -140px; bottom: -140px; width: 520px; height: 520px; border-radius: 50%; border: 1px solid rgba(226,167,30,.45); box-shadow: inset 0 0 0 40px rgba(226,167,30,.05), inset 0 0 0 41px rgba(226,167,30,.25); }
.login-art h1 { font-size: 44px; line-height: 1.1; margin: 0 0 12px; font-weight: 700; letter-spacing: -0.02em; max-width: 12ch; }
.login-art p { color: #c9d3f2; max-width: 38ch; margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.brand img { width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 0 0 2px var(--gold); }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--surface); }
.login-form { width: 100%; max-width: 360px; }
.login-form h2 { font-size: 26px; margin: 0 0 6px; letter-spacing: -0.01em; }
.login-form p { margin: 0 0 28px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.sidebar { background: var(--ink); color: #cdd6f4; padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; padding: 4px 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 12px; color: #7f8bb3; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-sm); color: #cdd6f4; font-weight: 500; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.active { background: #fff; color: var(--ink); }
.nav a.active svg { color: var(--royal); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; background: var(--gold); color: var(--ink); font-size: 12px; font-weight: 700; border-radius: 99px; padding: 0 7px; line-height: 20px; }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot button { background: none; border: 0; color: #cdd6f4; padding: 6px 0; cursor: pointer; }
.sidebar-foot button:hover { color: #fff; }

.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 28px 32px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0; letter-spacing: -0.015em; line-height: 1.2; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #c9cfdd; background: #fafbfd; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--royal); border-color: var(--royal); color: #fff; }
.btn-primary:hover { background: #1b39a9; border-color: #1b39a9; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: #f3c3c6; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #0f7a4c; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; height: 44px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input { height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; width: 100%; }
textarea.input { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.input:focus { outline: none; border-color: var(--royal); box-shadow: 0 0 0 3px var(--royal-soft); }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-prefix .input { padding-left: 28px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.form-error { color: var(--red); font-size: 14px; margin: -4px 0 14px; min-height: 0; }

/* ---------- Dashboard ---------- */
.flow { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink); color: #fff; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 18px; position: relative; }
.flow::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 -3px 0 var(--gold); pointer-events: none; }
.flow-item { padding: 22px 24px 24px; border-right: 1px solid rgba(255,255,255,.09); }
.flow-item:last-child { border-right: 0; }
.flow-item .k { color: #aeb9de; font-size: 14px; }
.flow-item .v { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; }
.flow-item .s { color: #aeb9de; font-size: 13px; margin-top: 6px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; margin-right: 6px; box-shadow: 0 0 0 4px rgba(61,220,132,.2); vertical-align: middle; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 18px; }
.stat { background: var(--surface); padding: 16px 20px; }
.stat .k { color: var(--muted); font-size: 14px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -0.01em; }
.stat.attention { background: var(--gold-soft); }
.stat.attention .v { color: #8a5a00; }
.stat a.v { display: block; color: inherit; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-body { padding: 20px; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--royal); }
.chart .bar.today { fill: var(--gold); }
.chart .bar:hover { fill: #1b39a9; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid { stroke: var(--line); }

/* ---------- Toolbar, tabs, tables ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.toolbar .input { max-width: 280px; height: 36px; }
.toolbar select.input { max-width: 180px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 7px 12px; border-radius: 99px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: 14px; }
.tab:hover { background: var(--paper); color: var(--text); }
.tab.active { background: var(--royal-soft); color: var(--royal); }
.tab .c { font-weight: 500; opacity: .8; margin-left: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbfbfd; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8f9fd; }
td.wrap { white-space: normal; min-width: 220px; }
.r { text-align: right; }
.person { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--royal-soft); color: var(--royal); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; object-fit: cover; font-size: 14px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.person .n { font-weight: 600; }
.person .e { font-size: 13px; color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.pager .btns { display: flex; gap: 8px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--paper); color: var(--muted); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--royal-soft); color: var(--royal); }
.pill .d { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.amt-pos { color: var(--green); font-weight: 600; }
.amt-neg { color: var(--red); font-weight: 600; }

/* ---------- Drawer & modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(14,27,61,.38); z-index: 40; animation: fade .15s ease-out; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--surface); z-index: 41; display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(14,27,61,.18); animation: slide .2s ease-out; }
.drawer-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.drawer-head .close { margin-left: auto; }
.drawer-body { padding: 20px 22px 40px; overflow-y: auto; flex: 1; }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 12px; }
.section-title:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.callout { background: var(--paper); border-radius: var(--radius); padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.callout .big { font-size: 22px; font-weight: 700; }
.mini-list { border: 1px solid var(--line); border-radius: var(--radius); }
.mini-list .row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.mini-list .row:last-child { border-bottom: 0; }

.modal { position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100% - 32px)); background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(14,27,61,.25); animation: pop .16s ease-out; }
.modal-head { padding: 18px 20px 0; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 20px 4px; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

.chat { background: var(--paper); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.astrologer { background: var(--royal); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.system, .bubble.birth { align-self: center; background: var(--gold-soft); color: #6b4a00; }
.bubble time { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }

.banners { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding: 20px; }
.banner-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.banner-card img { width: 100%; aspect-ratio: 2.2 / 1; object-fit: cover; display: block; background: var(--paper); }
.banner-card .meta { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5e3; border-radius: 99px; cursor: pointer; transition: .15s; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(18px); }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 11px 18px; border-radius: var(--radius); font-weight: 500; box-shadow: 0 8px 24px rgba(14,27,61,.3); animation: pop .16s ease-out; }
.toast.error { background: var(--red); }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--royal); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
.toast { animation-name: toastIn; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr; }
  .flow { grid-template-columns: repeat(2, 1fr); }
  .flow-item:nth-child(2) { border-right: 0; }
  .flow-item:nth-child(-n+2) { border-bottom: 1px solid rgba(255,255,255,.09); }
}
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 32px 24px; min-height: 260px; }
  .login-art h1 { font-size: 32px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 264px; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease-out; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(14,27,61,.4); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; display: flex; }
  .page { padding: 20px 16px 60px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; }
  .toolbar .input { max-width: none; flex: 1 1 160px; }
}
@media (max-width: 520px) {
  .flow { grid-template-columns: 1fr 1fr; }
  .flow-item { padding: 16px; }
  .flow-item .v { font-size: 24px; }
  .stats { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
