@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');
:root {
  color-scheme: light;
  --brand: #062640;
  --sand: #BAA899;
  --ocean: #648696;
  --ink: #1b3443;
  --muted: #6d7b82;
  --line: #e5dfd7;
  --surface: #fffdfa;
  --canvas: #f4f1ec;
  --soft: #f0ebe4;
  --accent: var(--brand);
  --accent-contrast: #fffdfa;
  --sidebar: var(--brand);
  --focus: var(--ocean);
}
body[data-theme="brand"] {
  --brand: #062640;
  --sand: #BAA899;
  --ocean: #648696;
  --ink: #1b3443;
  --muted: #6d7b82;
  --line: #e5dfd7;
  --surface: #fffdfa;
  --canvas: #f4f1ec;
  --soft: #f0ebe4;
  --accent: #062640;
  --sidebar: #062640;
}
body[data-theme="sand"] {
  --brand: #604b3c;
  --sand: #b99a7d;
  --ocean: #76857d;
  --ink: #3e342d;
  --muted: #786f66;
  --line: #e6dbcf;
  --surface: #fffaf4;
  --canvas: #f3ece3;
  --soft: #eee1d3;
  --accent: #70563f;
  --sidebar: #584538;
}
body[data-theme="ocean"] {
  --brand: #12394e;
  --sand: #c2ae9a;
  --ocean: #3e7881;
  --ink: #1a3947;
  --muted: #647b80;
  --line: #d9e3df;
  --surface: #fbfdfb;
  --canvas: #eaf1ee;
  --soft: #dce9e4;
  --accent: #286875;
  --sidebar: #12394e;
}
* { box-sizing: border-box; }
body { background: var(--canvas); color: var(--ink); font-family: Cairo, Tahoma, sans-serif; font-size: .94rem; transition: background-color .22s ease, color .22s ease; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--ocean); }
.shell { display: flex; min-height: 100vh; direction: rtl; }
.sidebar { width: 248px; min-width: 248px; padding: 1.25rem 1rem 1rem; background: var(--sidebar); color: #f8f5ef; display: flex; flex-direction: column; gap: 1.25rem; min-height: 100vh; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #f8f5ef; font-size: 1rem; font-weight: 800; display: flex; flex-direction: column; align-items: stretch; gap: .65rem; overflow-wrap: anywhere; }
.brand:hover { color: #fff; }
.brand-logo { display: block; width: 100%; height: 142px; object-fit: contain; padding: .35rem; border-radius: 1rem; background: #f7f2eb; }
.brand > span { padding-inline: .35rem; }
.side-caption { color: #d8d2c9; font-size: .78rem; padding-inline: .35rem; }
.sidebar .nav-link { color: #eee9e2; border-radius: .65rem; padding: .68rem .8rem; font-weight: 600; display: flex; align-items: center; border-inline-start: 3px solid transparent; transition: background-color .18s ease, color .18s ease; }
.sidebar .nav-link:hover, .sidebar .nav-link.active { color: #fff; background: rgb(255 255 255 / 12%); border-inline-start-color: var(--sand); }
.sidebar .mt-auto { padding-top: .8rem; border-top: 1px solid rgb(255 255 255 / 16%); }
.sidebar .btn-outline-light { --bs-btn-color: #f7f2eb; --bs-btn-border-color: rgb(255 255 255 / 36%); --bs-btn-hover-bg: rgb(255 255 255 / 12%); --bs-btn-hover-border-color: #f7f2eb; }
.main-content { min-width: 0; flex: 1; }
.topbar { min-height: 62px; padding: .85rem 2rem; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; justify-content: space-between; align-items: center; }
.mobile-brand { display: none; font-weight: 800; color: var(--ink); }
.content { max-width: 1460px; padding: 2rem; }
.page-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.6rem; }
.page-heading h1 { font-weight: 800; font-size: 1.7rem; margin: .25rem 0; letter-spacing: -.025em; }
.page-heading p { color: var(--muted); margin: .25rem 0 0; }
.eyebrow { font-size: .76rem; font-weight: 800; color: var(--ocean); letter-spacing: .02em; }
.panel, .stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: .9rem; box-shadow: 0 5px 18px rgb(25 45 54 / 4%); }
.panel { padding: 1.35rem; }
.section-heading { font-size: 1.12rem; font-weight: 800; margin-bottom: 1rem; }
.stat-card { padding: 1.15rem 1.25rem; min-height: 112px; display: flex; flex-direction: column; justify-content: space-between; border-top: 3px solid var(--sand); }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-value { font-size: clamp(1.4rem, 2vw, 1.95rem); color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.35; overflow-wrap: anywhere; }
.table { margin: 0; color: var(--ink); }
.table-responsive > .table { min-width: 550px; }
.table-sm, .table-borderless, .invoice-sheet table { min-width: auto; }
.invoice-totals-box { width: 100%; box-sizing: border-box; }
.table thead th { white-space: nowrap; background: var(--soft); color: var(--brand); font-weight: 800; border-bottom: 0; padding: .9rem .7rem; }
.table td { padding: .75rem .7rem; border-color: var(--line); }
.table tbody tr:hover { background: color-mix(in srgb, var(--soft) 60%, var(--surface)); }
.table-responsive { border-radius: .7rem; }
.empty { text-align: center; padding: 2rem !important; color: var(--muted) !important; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.actions form { margin: 0; }
.inline-adjust { display: flex; gap: .35rem; align-items: center; }
.inline-adjust input { width: 6rem; }
.small-number { width: 5rem; }
.qty-input { width: 6rem; }
.form-panel { max-width: 880px; }
.form-label { font-weight: 700; color: var(--ink); }
.form-control, .form-select { padding: .6rem .8rem; border-color: var(--line); border-radius: .65rem; background-color: var(--surface); color: var(--ink); }
.form-control:focus, .form-select:focus { border-color: var(--ocean); box-shadow: 0 0 0 .22rem color-mix(in srgb, var(--ocean) 20%, transparent); }
.btn { border-radius: .65rem; font-weight: 700; padding: .55rem .95rem; }
.btn-sm { padding: .32rem .65rem; white-space: nowrap; }
.btn-primary { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); --bs-btn-color: var(--accent-contrast); }
.btn-outline-primary { --bs-btn-color: var(--accent); --bs-btn-border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); --bs-btn-hover-bg: var(--accent); --bs-btn-hover-border-color: var(--accent); }
.wallet-setting { background: var(--soft); border: 1px solid var(--line); border-radius: .75rem; padding: 1rem; }
.percent-input { max-width: 8rem; }
.pre-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.reminders-panel { border-inline-start: 4px solid var(--sand); }
.reminders-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.reminder-count { flex: 0 0 auto; padding: .35rem .7rem; border-radius: 999px; color: var(--brand); background: var(--soft); font-size: .8rem; font-weight: 800; }
.reminder-list { display: grid; gap: .55rem; }
.reminder-item { display: grid; grid-template-columns: minmax(105px, .75fr) minmax(140px, 1.3fr) minmax(120px, .9fr) auto auto; align-items: center; gap: 1rem; padding: .85rem 1rem; color: var(--ink); background: color-mix(in srgb, var(--soft) 45%, var(--surface)); border: 1px solid var(--line); border-radius: .7rem; transition: border-color .18s ease, background-color .18s ease; }
.reminder-item:hover { color: var(--ink); background: var(--soft); border-color: var(--sand); }
.reminder-date { color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.reminder-customer { font-weight: 800; overflow-wrap: anywhere; }
.reminder-due { display: flex; flex-direction: column; gap: .05rem; font-variant-numeric: tabular-nums; }
.reminder-due-label { color: var(--muted); font-size: .72rem; }
.reminder-due strong { color: var(--brand); }
.reminder-timing { white-space: nowrap; color: var(--brand); background: color-mix(in srgb, var(--sand) 28%, var(--surface)); border-radius: 999px; padding: .3rem .65rem; font-size: .78rem; font-weight: 800; }
.reminder-timing.is-today { background: #f5e8dc; color: #7f442e; }
.reminder-open { color: var(--accent); font-size: .82rem; font-weight: 800; white-space: nowrap; }
.reminders-empty { display: flex; flex-direction: column; gap: .25rem; padding: 1.15rem; color: var(--ink); background: var(--soft); border-radius: .7rem; }
.reminders-empty span { color: var(--muted); font-size: .86rem; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(ellipse at 14% 85%, color-mix(in srgb, var(--sand) 34%, transparent) 0%, transparent 38%), var(--canvas); }
.login-card { width: min(100%, 460px); border: 1px solid var(--line) !important; border-radius: 1rem; background: var(--surface); box-shadow: 0 22px 60px rgb(6 38 64 / 12%) !important; }
.login-card .card-body { padding: clamp(1.5rem, 6vw, 3rem) !important; }
.login-brand { width: 100%; max-width: 250px; margin: 0 auto 1.5rem; padding: .6rem; border-radius: .9rem; background: #f7f2eb; }
.login-brand img { display: block; width: 100%; height: auto; }
.login-card h1 { color: var(--brand); font-weight: 800; }
.login-card p { color: var(--muted) !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Mobile Drawer & Backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 20, 30, 0.65);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}
.sidebar-mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.65rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

body.mobile-drawer-open {
  overflow: hidden;
}

@media (max-width: 991.98px) {
  .shell { display: block; }
  .sidebar {
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    width: 290px !important;
    max-width: 86vw;
    height: 100vh !important;
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -6px 0 28px rgba(0, 0, 0, 0.35);
    padding: 1.25rem 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .brand { flex-direction: row; align-items: center; gap: .65rem; font-size: .95rem; }
  .brand-logo { width: 50px; height: 50px; padding: .2rem; border-radius: .6rem; }
  .sidebar .nav { flex-direction: column !important; gap: .25rem !important; }
  .sidebar .nav-link { padding: .65rem .85rem; font-size: .9rem; border-inline-start: 3px solid transparent; min-height: 44px; }
  .sidebar .nav-link:hover, .sidebar .nav-link.active { border-inline-start-color: var(--sand); background: rgb(255 255 255 / 12%); }
  .sidebar .mt-auto { display: block; padding-top: .8rem; margin-top: auto; }
  .sidebar .mt-auto button { width: 100% !important; min-height: 44px; }
  .side-caption { display: none; }
  
  .topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: 56px;
    padding: .5rem .85rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .mobile-brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 0.95rem; }
  .mobile-brand img { width: 36px; height: 36px; object-fit: contain; padding: 2px; border-radius: .4rem; background: #f7f2eb; }
  .mobile-nav-toggle {
    display: inline-flex !important;
    align-items: center;
    padding: .35rem .7rem;
    font-size: .88rem;
    border-radius: .55rem;
    color: var(--ink);
    border-color: var(--line);
    background: var(--soft);
  }
  .content { padding: 1.1rem .85rem; }
}

@media (max-width: 768px) {
  /* Prevent iOS zoom on inputs */
  input, select, textarea {
    font-size: 16px !important;
  }
  .form-control, .form-select, .btn {
    min-height: 44px;
  }
  .btn-sm {
    min-height: 36px;
    padding: .35rem .7rem;
  }
  .page-heading {
    flex-direction: column;
    align-items: stretch;
    gap: .75rem;
    margin-bottom: 1.15rem;
  }
  .page-heading h1 { font-size: 1.35rem; }
  .page-heading > .btn, .page-heading > div > .btn, .page-heading > .d-flex > .btn, .page-heading > .d-flex {
    width: 100%;
    justify-content: center;
  }
  .panel { padding: 1rem .85rem; }
  .stat-card { padding: 1rem .85rem; min-height: 100px; }
  .stat-value { font-size: 1.55rem; }
  
  .reminders-heading { align-items: flex-start; }
  .reminder-item { grid-template-columns: minmax(0, 1fr) auto; gap: .45rem .75rem; padding: .8rem; }
  .reminder-date { grid-column: 1; grid-row: 1; }
  .reminder-timing { grid-column: 2; grid-row: 1; }
  .reminder-customer { grid-column: 1; grid-row: 2; }
  .reminder-due { grid-column: 1; grid-row: 3; }
  .reminder-open { grid-column: 2; grid-row: 3; justify-self: end; }

  /* Invoice mobile view */
  .invoice-sheet {
    padding: 1.25rem .75rem !important;
    border-radius: .75rem !important;
    margin-bottom: 1rem !important;
  }
  .invoice-header-grid {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
  }
  .invoice-totals-box {
    padding: .85rem !important;
    margin-top: .75rem;
  }
}

@media (max-width: 480px) {
  .content { padding: .85rem .5rem; }
  .panel { padding: .85rem .65rem; border-radius: .7rem; }
  .table td, .table th { padding: .6rem .45rem; font-size: .84rem; }
  .actions { gap: .25rem; }
  .app-tribute-footer { padding: 1rem .5rem; margin-top: 1.5rem; }
  .tribute-text { font-size: .84rem; }
}

/* Invoice Styles */
.invoice-sheet {
  background: #ffffff !important;
  color: #1a252f !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.invoice-logo {
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.letter-spacing-1 {
  letter-spacing: 0.05em;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .sidebar, .topbar, .page-heading, .d-print-none, .alert, .btn-close {
    display: none !important;
  }
  .shell, .main-content, .content, .invoice-wrapper {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}

/* App Tribute Footer */
.app-tribute-footer {
  margin-top: 2.5rem;
  padding: 1.25rem 1rem;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 95%, var(--sand));
  border-radius: .7rem;
}
.tribute-text {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.7;
}
.tribute-name {
  color: var(--brand);
  font-weight: 800;
  letter-spacing: 0.2px;
}
.tribute-icon {
  display: inline-block;
  margin: 0 4px;
}

