:root {
  color-scheme: light;
  --ink: #17363a;
  --ink-soft: #50686a;
  --muted: #809392;
  --canvas: #f3f6f3;
  --paper: #ffffff;
  --line: #e2e9e4;
  --brand: #136b60;
  --brand-dark: #0d514a;
  --brand-light: #e3f1ec;
  --gold: #d6a850;
  --gold-soft: #fbf4e7;
  --danger: #bd514c;
  --danger-soft: #fff0ee;
  --blue-soft: #eaf1f8;
  --shadow: 0 12px 38px rgba(21, 55, 53, .07);
  font-family: Tahoma, Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(19, 107, 96, .24);
  outline-offset: 2px;
}
a { color: inherit; }
.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--ink-soft); }
.boot-screen p { margin: 0; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px 16px 16px 5px; color: white; background: var(--brand); font-size: 27px; font-weight: 800; }

/* Secure first-run and unlock screens */
.auth-shell {
  min-height: 100vh; display: grid; grid-template-columns: minmax(330px, .92fr) 1.08fr;
  background: var(--paper);
}
.auth-story {
  position: relative; overflow: hidden; padding: clamp(32px, 6vw, 82px);
  color: #f6fbf8; background: #102f35;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-story::before, .auth-story::after {
  content: ""; position: absolute; border: 1px solid rgba(225, 190, 117, .19); border-radius: 50%;
  width: 430px; height: 430px; left: -150px; bottom: -190px;
}
.auth-story::after { width: 320px; height: 320px; left: -95px; bottom: -135px; }
.auth-brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.auth-brand .brand-mark { background: var(--gold); color: #18373a; }
.auth-brand strong { font-size: 20px; letter-spacing: -.5px; }
.auth-brand span { display: block; color: #aec4bf; font-size: 12px; margin-top: 3px; }
.story-copy { position: relative; z-index: 1; max-width: 520px; padding: 50px 0; }
.eyebrow { color: #d9bc7c; letter-spacing: .04em; font-size: 13px; }
.story-copy h1 { font-size: clamp(32px, 4.4vw, 56px); line-height: 1.28; margin: 18px 0; max-width: 480px; }
.story-copy p { max-width: 390px; color: #b5c8c3; line-height: 1.9; font-size: 15px; }
.story-foot { position: relative; z-index: 1; color: #91aaa5; font-size: 12px; }
.auth-content { min-height: 100vh; display: grid; place-items: center; padding: 36px 24px; }
.auth-card { width: min(100%, 440px); }
.auth-card h2 { margin: 0 0 8px; font-size: 28px; }
.auth-card > p { margin: 0 0 28px; color: var(--ink-soft); line-height: 1.8; }
.auth-card .field { margin-bottom: 17px; }
.auth-card .btn-primary { width: 100%; margin-top: 8px; }
.security-note { display: flex; gap: 10px; padding: 13px 14px; margin-top: 20px; background: #f2f7f4; border-radius: 12px; color: var(--ink-soft); line-height: 1.7; font-size: 12px; }
.security-icon { color: var(--brand); font-size: 16px; font-weight: 700; }
.auth-error { min-height: 20px; color: var(--danger); font-size: 13px; margin: 4px 0; }

/* Main application frame */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 23px 14px 16px; display: flex; flex-direction: column;
  background: #102f35; color: #dce9e4; z-index: 4;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 0 9px 25px; border-bottom: 1px solid rgba(255,255,255,.09); }
.side-brand .brand-mark { flex: none; width: 39px; height: 39px; border-radius: 13px 13px 13px 4px; background: var(--gold); color: #18373a; font-size: 21px; }
.side-brand strong { font-size: 17px; }
.side-brand small { display: block; color: #a4bab4; margin-top: 3px; font-size: 11px; }
.nav-caption { color: #7f9b95; font-size: 10px; letter-spacing: .08em; padding: 21px 11px 8px; }
.nav-list { display: grid; gap: 4px; }
.nav-item {
  width: 100%; border: 0; border-radius: 10px; background: transparent; color: #c3d2cd;
  display: flex; align-items: center; gap: 11px; padding: 11px 12px; text-align: right; transition: .18s ease;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: #1e514e; color: #fff; box-shadow: inset -3px 0 var(--gold); }
.nav-glyph { width: 20px; display: inline-grid; place-items: center; color: #99b8ad; font-size: 15px; }
.nav-item.active .nav-glyph { color: #e2c27e; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255,255,255,.09); padding: 13px 4px 0; }
.vault-status { display: flex; align-items: center; gap: 8px; font-size: 11px; color: #a9c0b9; padding: 8px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #72c49b; box-shadow: 0 0 0 4px rgba(114,196,155,.12); }
.sidebar-lock { width: 100%; display: flex; gap: 10px; align-items: center; border: 0; color: #c5d2cf; background: transparent; padding: 10px 11px; border-radius: 9px; text-align: right; }
.sidebar-lock:hover { background: rgba(255,255,255,.07); }

.main-area { min-width: 0; }
.topbar {
  height: 76px; display: flex; justify-content: space-between; align-items: center; gap: 20px;
  padding: 0 clamp(20px, 3.5vw, 48px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.8);
}
.top-title h1 { margin: 0; font-size: 20px; }
.top-title p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.company-chip { display: flex; align-items: center; gap: 8px; max-width: 240px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; background: #fff; color: var(--ink-soft); font-size: 12px; }
.company-chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.main-content { max-width: 1480px; margin: 0 auto; padding: 28px clamp(20px, 3.5vw, 48px) 55px; }
.content-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.content-heading h2 { font-size: 24px; margin: 0 0 6px; }
.content-heading p { color: var(--muted); margin: 0; font-size: 13px; }
.button-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.btn {
  min-height: 39px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 9px;
  padding: 8px 13px; border: 1px solid var(--line); color: var(--ink); background: #fff; font-size: 12px; font-weight: 700;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 12px rgba(20,53,51,.08); }
.btn-primary { color: #fff; border-color: var(--brand); background: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-soft { border-color: transparent; color: var(--brand); background: var(--brand-light); }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn-small { min-height: 31px; padding: 5px 9px; font-size: 11px; }
.btn-icon { min-width: 34px; padding: 5px; }
.icon-plus { font-size: 18px; line-height: 12px; font-weight: 400; }
.toolbar { display: flex; gap: 10px; align-items: center; }
.search-box { width: min(280px, 33vw); position: relative; }
.search-box input { width: 100%; height: 39px; border: 1px solid var(--line); border-radius: 9px; padding: 0 35px 0 12px; background: #fff; color: var(--ink); font-size: 12px; }
.search-box::before { content: "⌕"; position: absolute; right: 12px; top: 5px; color: #819491; font-size: 21px; }

/* Dashboard */
.welcome-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 22px; overflow: hidden;
  background: #e8f1ea; border: 1px solid #dbe8dd; border-radius: 15px; padding: 20px 24px; margin-bottom: 20px;
  position: relative;
}
.welcome-banner::after { content: ""; position: absolute; width: 150px; height: 150px; border: 1px solid #d3e2d6; border-radius: 50%; left: 14%; top: -95px; }
.welcome-text { position: relative; z-index: 1; }
.welcome-text small { color: var(--brand); font-weight: 700; }
.welcome-text h2 { font-size: 19px; margin: 7px 0 5px; }
.welcome-text p { font-size: 12px; color: var(--ink-soft); margin: 0; line-height: 1.8; }
.welcome-actions { position: relative; z-index: 1; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-bottom: 20px; }
.metric-card { min-width: 0; border: 1px solid var(--line); background: var(--paper); border-radius: 13px; padding: 17px 17px 15px; box-shadow: 0 3px 10px rgba(21,55,53,.025); }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metric-label { color: var(--ink-soft); font-size: 12px; }
.metric-symbol { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: var(--brand-light); color: var(--brand); font-weight: 800; }
.metric-symbol.gold { color: #9a722c; background: var(--gold-soft); }
.metric-value { font-weight: 800; font-size: clamp(18px, 2vw, 24px); margin: 13px 0 5px; direction: ltr; text-align: right; overflow-wrap: anywhere; }
.metric-note { color: var(--muted); font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(255px, .85fr); gap: 15px; }
.panel { border: 1px solid var(--line); background: var(--paper); border-radius: 13px; padding: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-size: 14px; }
.panel-head small { color: var(--muted); }
.quick-actions { display: grid; gap: 9px; }
.quick-action {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px; border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); background: white; text-align: right; transition: .16s ease;
}
.quick-action:hover { border-color: #bdd8ce; background: #f8fbf9; }
.quick-glyph { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; color: var(--brand); background: var(--brand-light); font-weight: 800; }
.quick-action b { display: block; font-size: 12px; }
.quick-action small { display: block; color: var(--muted); margin-top: 4px; font-size: 10px; }
.stock-alert { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 11px; }

/* Data tables and lists */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { text-align: right; color: var(--muted); font-size: 10px; font-weight: 700; padding: 10px 9px; border-bottom: 1px solid var(--line); }
td { padding: 12px 9px; border-bottom: 1px solid #edf1ee; color: var(--ink-soft); font-size: 11px; }
tr:last-child td { border-bottom: 0; }
td strong { color: var(--ink); font-weight: 700; }
.amount { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.table-actions { display: flex; align-items: center; gap: 5px; }
.type-pill, .state-pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 20px; padding: 5px 8px; font-size: 10px; font-weight: 700; }
.type-import, .state-draft { color: #8d6928; background: #faf1db; }
.type-export, .state-paid { color: #24734e; background: #e5f3e9; }
.type-expense, .state-overdue { color: #aa4541; background: #fce9e7; }
.type-income, .state-pending { color: #416f92; background: #eaf1f8; }
.state-partial { color: #7d6095; background: #f1eaf7; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink-soft); margin: 10px 0 6px; font-size: 13px; }
.empty-mark { width: 43px; height: 43px; margin: auto; display: grid; place-items: center; border-radius: 14px; background: #f0f5f2; color: var(--brand); font-weight: 800; font-size: 19px; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.filter-select, .field input, .field select, .field textarea { min-height: 39px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #dce5df; border-radius: 8px; }
.filter-select { font-size: 11px; }
.table-card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table-card .table-wrap { padding: 0 12px; }
.table-card table { min-width: 760px; }
.table-card td:first-child, .table-card th:first-child { padding-right: 12px; }
.table-footer { display: flex; justify-content: space-between; gap: 10px; padding: 12px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.section-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.report-card { padding: 19px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.report-card h3 { margin: 0 0 7px; font-size: 14px; }
.report-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.8; }
.report-total { margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; font-size: 11px; color: var(--ink-soft); }
.bar-list { display: grid; gap: 12px; margin-top: 17px; }
.bar-row { display: grid; grid-template-columns: 75px 1fr auto; align-items: center; gap: 9px; font-size: 10px; color: var(--ink-soft); }
.bar-track { height: 7px; border-radius: 10px; background: #eef3ef; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--brand); }
.bar-w-0 { width: 0%; }
.bar-w-10 { width: 10%; }
.bar-w-20 { width: 20%; }
.bar-w-30 { width: 30%; }
.bar-w-40 { width: 40%; }
.bar-w-50 { width: 50%; }
.bar-w-60 { width: 60%; }
.bar-w-70 { width: 70%; }
.bar-w-80 { width: 80%; }
.bar-w-90 { width: 90%; }
.bar-w-100 { width: 100%; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(250px, .8fr); gap: 15px; align-items: start; }
.settings-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 14px; }
.settings-card h3 { font-size: 14px; margin: 0 0 7px; }
.settings-card > p { color: var(--muted); line-height: 1.8; font-size: 11px; margin: 0 0 17px; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.privacy-callout { background: #f4f7f4; border-right: 3px solid var(--brand); border-radius: 8px; padding: 13px; line-height: 1.8; color: var(--ink-soft); font-size: 11px; }
.warning-callout { background: var(--gold-soft); border-right: 3px solid var(--gold); }

/* Forms, dialogs and feedback */
.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: rgba(10,32,34,.52); backdrop-filter: blur(3px); animation: fade-in .16s ease-out; }
.modal { width: min(100%, 590px); max-height: min(90vh, 800px); overflow: auto; border-radius: 15px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,.2); animation: rise-in .18s ease-out; }
.modal-wide { width: min(100%, 730px); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 19px 21px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.modal-close { width: 31px; height: 31px; border: 0; border-radius: 8px; background: #f1f5f2; color: var(--ink-soft); font-size: 19px; }
.modal-form { padding: 20px 21px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; font-size: 12px; }
.field textarea { resize: vertical; min-height: 74px; line-height: 1.6; }
.field-help { color: var(--muted); font-size: 10px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-start; gap: 8px; padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--line); }
.toast-stack { position: fixed; z-index: 20; left: 20px; bottom: 20px; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: min(380px, calc(100vw - 40px)); padding: 12px 16px; border-radius: 10px; color: #fff; background: #173d39; box-shadow: 0 9px 28px rgba(15,47,43,.2); font-size: 12px; line-height: 1.7; animation: rise-in .18s ease-out; }
.toast.error { background: #a73f3b; }
.mobile-nav-toggle { display: none; }
.required { color: var(--danger); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 215px minmax(0, 1fr); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-story { min-height: 230px; padding: 25px 24px; }
  .story-copy { padding: 28px 0 10px; }
  .story-copy h1 { font-size: 31px; margin: 10px 0; }
  .story-copy p, .story-foot { display: none; }
  .auth-content { min-height: auto; padding: 35px 22px 46px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 245px; height: 100dvh; transform: translateX(-105%); transition: transform .22s ease; box-shadow: 10px 0 32px rgba(0,0,0,.15); }
  .sidebar.open { transform: translateX(0); }
  .mobile-nav-toggle { display: inline-flex; width: 36px; height: 36px; align-items: center; justify-content: center; padding: 0; border: 1px solid var(--line); background: white; border-radius: 9px; color: var(--ink); font-size: 18px; }
  .topbar { height: 68px; padding: 0 16px; }
  .top-title { flex: 1; }
  .top-title h1 { font-size: 16px; }
  .top-title p { display: none; }
  .company-chip { display: none; }
  .main-content { padding: 20px 15px 40px; }
  .content-heading { align-items: flex-start; flex-direction: column; }
  .content-heading h2 { font-size: 21px; }
  .search-box { width: 100%; }
  .toolbar { width: 100%; }
  .section-grid, .settings-grid { grid-template-columns: 1fr; }
  .welcome-banner { align-items: flex-start; flex-direction: column; padding: 17px; }
}
@media (max-width: 480px) {
  .metrics-grid { gap: 9px; }
  .metric-card { padding: 13px; }
  .metric-value { font-size: 17px; }
  .metric-label { font-size: 10px; }
  .button-row { width: 100%; }
  .button-row .btn { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .auth-card h2 { font-size: 24px; }
  .panel { padding: 14px; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { min-width: auto; background: #fff; color: #111; }
  .sidebar, .topbar, .content-heading .button-row, .toolbar, .table-actions, .quick-actions, .welcome-actions, .toast-stack, .mobile-nav-toggle { display: none !important; }
  .app-shell { display: block; }
  .main-content { padding: 0; max-width: none; }
  .content-heading { margin: 0 0 12px; }
  .panel, .metric-card, .table-card, .report-card { box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .table-card table { min-width: 0; white-space: normal; }
  th, td { padding: 7px 5px; font-size: 9pt; color: #222; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
  .welcome-banner { display: none; }
  .main-area::before { content: "مرفأ — نسخة للطباعة"; display: block; margin-bottom: 12px; font-size: 13pt; font-weight: 700; }
}
