:root {
  /* LILVA brand system (LILVA-BRAND-SYSTEM.md) */
  --ink: #0E2B36;
  --ink-2: #143846;
  --ink-deep: #050B0F;
  --cream: #F5EFE2;
  --cream-deep: #ECE3CF;
  --gold: #C3965B;
  --gold-light: #D6AE7A;
  --gold-glow: #E8CC9A;
  --gold-wash: #F4E4C2;
  --teal: #1D7A8C;
  --teal-deep: #0E4956;

  --navy: var(--ink);
  --navy-2: var(--ink-2);
  --gold-soft: var(--gold-wash);
  --bg: #F8F4EC;
  --card: #FFFDF9;
  --ink-text: #16252B;
  --muted: #6B7A7F;
  --line: #E7DECB;
  --green: #3F8F6E;
  --green-soft: #E4F1EA;
  --red: #B23A3A;
  --red-soft: #F7E6E3;
  --amber: #C9933A;
  --amber-soft: #FAEFD9;
  --blue: var(--teal);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(14, 43, 54, .05), 0 6px 20px rgba(14, 43, 54, .06);
  --font: "IBM Plex Sans Arabic", "Geist", Tahoma, sans-serif;
  --font-latin: "Geist", "IBM Plex Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink-text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.num { font-family: var(--font-latin); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- controls ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink-text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: #FFFEFB; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(29, 122, 140, .18); border-color: var(--teal); }
.btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); color: var(--ink-text); border-color: var(--line); white-space: nowrap; text-decoration: none; transition: background .15s, border-color .15s, transform .1s;
}
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--ink); color: var(--cream); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn-lg { padding: 13px 18px; font-size: 16px; }
.btn-gold { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.btn-gold:hover { background: var(--gold-light); border-color: var(--gold-light); }
.btn-danger { background: var(--card); color: var(--red); border-color: #f0c9c6; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: inherit; }
.icon-btn:hover { background: rgba(0, 0, 0, .05); }
.form-error { color: var(--red); background: var(--red-soft); padding: 8px 12px; border-radius: 8px; margin: 0; font-size: 14px; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.chip-green { background: var(--green-soft); color: var(--green); }
.chip-red { background: var(--red-soft); color: var(--red); }
.chip-amber { background: var(--amber-soft); color: var(--amber); }
.segmented { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { font: inherit; font-size: 13px; border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--ink); color: var(--cream); }

/* ---------- splash ---------- */
.splash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: radial-gradient(circle at 50% 45%, var(--ink) 0%, #0A1E26 55%, var(--ink-deep) 100%); transition: opacity .6s ease, visibility .6s; }
.splash.done { opacity: 0; visibility: hidden; }
.splash-inner { position: relative; display: grid; place-items: center; }
.splash-mark { width: 96px; grid-area: 1 / 1; animation: markIn 1s cubic-bezier(.2, .8, .2, 1) both, markOut .5s ease 1.05s forwards; }
.splash-lockup { width: min(340px, 72vw); grid-area: 1 / 1; opacity: 0; animation: lockIn .8s cubic-bezier(.2, .8, .2, 1) 1.15s forwards; }
.splash-line { position: absolute; bottom: -34px; width: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-glow), transparent); animation: line .9s ease 1.4s forwards; }
@keyframes markIn { from { opacity: 0; transform: scale(.7); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes markOut { to { opacity: 0; transform: scale(.9); } }
@keyframes lockIn { from { opacity: 0; transform: translateY(8px); letter-spacing: .1em; } to { opacity: 1; transform: none; } }
@keyframes line { to { width: min(260px, 60vw); } }
@media (prefers-reduced-motion: reduce) {
  .splash-mark { display: none; }
  .splash-lockup { animation: none; opacity: 1; }
  .splash-line { display: none; }
}

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); background: var(--bg); }
.auth-visual { position: relative; overflow: hidden; background: radial-gradient(900px 600px at 30% 20%, #1A4453 0%, var(--ink) 45%, var(--ink-deep) 100%); color: var(--cream); padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 26px; }
.auth-visual::after { content: ""; position: absolute; inset-inline-end: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(195, 150, 91, .22), transparent 65%); pointer-events: none; }
.auth-lockup { width: min(300px, 70%); animation: fadeUp .7s ease both; }
.auth-tagline { font-size: 28px; font-weight: 600; line-height: 1.45; max-width: 420px; animation: fadeUp .7s ease .08s both; }
.auth-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; color: #D9D2C3; animation: fadeUp .7s ease .16s both; }
.auth-points li { display: flex; align-items: center; gap: 12px; }
.auth-points .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 4px rgba(195, 150, 91, .18); }
.auth-foot { position: absolute; bottom: 24px; inset-inline-start: 56px; margin: 0; font-size: 12px; color: #8FA3A8; }
.auth-panel { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: 0 20px 50px rgba(14, 43, 54, .08); animation: fadeUp .6s ease .1s both; }
.auth-card h1 { font-size: 24px; color: var(--ink); }
.auth-mobile-logo { display: none; width: 170px; margin: 0 auto 22px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-inline-end: 44px; }
.pw-toggle { position: absolute; inset-block: 0; inset-inline-end: 6px; border: 0; background: transparent; cursor: pointer; font-size: 16px; opacity: .55; }
.pw-toggle:hover { opacity: .9; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 17px; font-family: var(--font-latin); letter-spacing: .12em; }
.brand small { display: block; font-size: 12px; opacity: .7; }
.brand-mark { width: 38px; height: auto; }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-panel { min-height: 100vh; background: radial-gradient(700px 400px at 50% 0%, var(--cream-deep), var(--bg)); }
  .auth-mobile-logo { display: block; }
  .auth-card { padding: 24px; }
}

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100%; }
.sidebar { background: linear-gradient(180deg, var(--ink) 0%, #0B222B 100%); color: #DCD6C8; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 4px 8px 18px; color: var(--cream); }
nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 11px; letter-spacing: .03em; text-transform: uppercase; color: #7E969C; padding: 14px 10px 6px; font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: #DCD6C8; text-decoration: none; font-weight: 500; cursor: pointer; border: 0; background: transparent; font: inherit; text-align: start; width: 100%; }
.nav-link:hover { background: rgba(255, 255, 255, .06); }
.nav-link.active { background: rgba(195, 150, 91, .16); color: var(--gold-light); box-shadow: inset -3px 0 0 var(--gold); }
.nav-link .ico { width: 20px; text-align: center; }
.nav-link .soon { margin-inline-start: auto; font-size: 10px; background: rgba(255, 255, 255, .1); padding: 1px 6px; border-radius: 6px; color: #b9c9d6; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.me { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.me strong { display: block; font-size: 14px; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me small { display: block; font-size: 12px; color: #8aa3b5; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ink-2); color: var(--gold-light); border: 1px solid rgba(195,150,91,.35); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.sidebar .btn-ghost { color: #b9c9d6; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 16px 28px; background: var(--bg); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid transparent; }
.topbar h2 { font-size: 21px; }
.topbar-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }
.view { padding: 4px 28px 40px; display: flex; flex-direction: column; gap: 18px; }
.scrim { display: none; }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h3 { font-size: 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 27px; font-weight: 600; margin-top: 4px; font-family: var(--font-latin); color: var(--ink); }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: radial-gradient(500px 200px at 20% 0%, #1A4453, var(--ink)); color: var(--cream); }
.kpi.accent .label, .kpi.accent .sub { color: #B9C4C2; }
.kpi.accent .value { color: var(--gold-light); }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 240px; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.alert.warn { background: var(--amber-soft); color: #7a5316; }
.alert.bad { background: var(--red-soft); color: #8d2f2a; }
.alert.ok { background: var(--green-soft); color: #196a47; }
.alert button { margin-inline-start: auto; }

.meter { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.meter > span { display: block; height: 100%; background: var(--green); border-radius: 999px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: start; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #FBF7EF; }
td.wrap { white-space: normal; min-width: 160px; }
.empty { text-align: center; padding: 36px 10px; color: var(--muted); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 160px; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

/* ---------- add entry ---------- */
.dropzone { border: 2px dashed #D8CCB2; border-radius: var(--radius); padding: 28px 16px; text-align: center; background: #FCF9F3; cursor: pointer; transition: .15s; }
.dropzone.drag { border-color: var(--teal); background: #EDF5F3; }
.dropzone .big { font-size: 34px; }
.preview { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); }
.entry-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.entry-card .full { grid-column: 1 / -1; }

/* ---------- drawer ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 30; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(14, 43, 54, .4); backdrop-filter: blur(2px); }
.drawer { position: absolute; inset-block: 0; inset-inline-end: 0; width: min(520px, 100%); background: var(--card); display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0, 0, 0, .15); }
.drawer header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer header h3 { flex: 1; }
.drawer-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.receipts { display: flex; flex-direction: column; gap: 10px; }
.receipts img { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--cream); padding: 10px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--red); color: #fff; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(0, 0, 0, .15); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px; color: var(--muted); }
.soon-hero { text-align: center; padding: 40px 20px; }
.soon-hero .big { font-size: 44px; }
.feature-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 18px; text-align: start; }
.feature-list .card { box-shadow: none; border: 1px solid var(--line); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3-1 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 270px; z-index: 20; transform: translateX(110%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 15; }
  .menu-btn { display: inline-block; }
  .topbar { padding: 12px 16px; }
  .topbar h2 { font-size: 18px; }
  .view { padding: 4px 16px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
}
@media (max-width: 460px) {
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
}
