/* Hisab Kitab Portal — modern dark UI, mobile-first */
:root {
  color-scheme: dark;
  --bg: #0a0e17;
  --bg2: #0f1524;
  --card: #141c30;
  --card2: #1a2440;
  --border: #22304f;
  --text: #f1f5f9;
  --muted: #8b98b8;
  --green: #22c55e;
  --green-d: #052e16;
  --blue: #3b82f6;
  --blue-d: #0b2447;
  --amber: #f59e0b;
  --amber-d: #451a03;
  --red: #ef4444;
  --red-d: #450a0a;
  --purple: #a855f7;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(59,130,246,.08), transparent);
  min-height: 100vh; padding-bottom: 76px;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 12px 14px; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; }
.top h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.5px;
  background: linear-gradient(135deg, #fff, #93c5fd); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.top h1 .green, .green { color: var(--green) !important; -webkit-text-fill-color: var(--green); }
.top a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 8px 12px; border-radius: 8px; }
.top a:active { background: var(--card); }

/* Nav — desktop pills, mobile bottom bar */
.nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.nav a { color: var(--muted); text-decoration: none; padding: 10px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; transition: all .15s; }
.nav a.active { background: linear-gradient(135deg, #166534, #15803d); color: #fff; box-shadow: 0 2px 12px rgba(34,197,94,.3); }
.nav a:not(.active):active { background: var(--card); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.card { background: linear-gradient(160deg, var(--card), var(--bg2)); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); transition: transform .15s; }
.card:active { transform: scale(.98); }
.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; font-weight: 600; }
.card .val { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.val.blue { color: var(--blue); } .val.green { color: var(--green); }
.val.amber { color: var(--amber); } .val.red { color: var(--red); }
.amber { color: var(--amber); } .red { color: var(--red); } .blue { color: var(--blue); }

/* Headings */
h2 { font-size: 19px; margin: 20px 0 12px; font-weight: 700; letter-spacing: -.3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn { display: inline-block; background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; border: 0;
  padding: 12px 20px; border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 700;
  text-decoration: none; box-shadow: 0 2px 12px rgba(34,197,94,.25); transition: all .15s; min-height: 44px; }
.btn:active { transform: scale(.97); box-shadow: none; }
.btn.secondary { background: var(--card2); box-shadow: none; border: 1px solid var(--border); }
.btn.danger { background: linear-gradient(135deg, #dc2626, #991b1b); box-shadow: 0 2px 12px rgba(239,68,68,.25); }
.btn.small { padding: 8px 14px; font-size: 13px; min-height: 38px; border-radius: 9px; }

/* Forms */
.frm { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.frm label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.frm label:first-child { margin-top: 0; }
.frm input, .frm select, .frm textarea {
  width: 100%; background: var(--bg2); border: 1.5px solid var(--border); color: var(--text);
  padding: 13px 14px; border-radius: 10px; font-size: 16px; font-family: inherit; transition: border .15s, box-shadow .15s;
}
.frm input:focus, .frm select:focus, .frm textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
.frm textarea { min-height: 80px; resize: vertical; }
.frm .btn { margin-top: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Search bar */
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.searchbar input, .searchbar select { background: var(--bg2); border: 1.5px solid var(--border); color: var(--text);
  padding: 11px 13px; border-radius: 10px; font-size: 14px; font-family: inherit; }
.searchbar input { flex: 2; min-width: 160px; }
.searchbar input:focus, .searchbar select:focus { outline: none; border-color: var(--green); }

/* Tables — desktop */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; font-size: 14px; box-shadow: var(--shadow); }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: rgba(255,255,255,.03); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:active { background: rgba(255,255,255,.02); }
td.actions { white-space: normal; }
/* Table scroll container — prevents page-level horizontal scroll */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 16px; border-radius: var(--radius); }
.table-wrap table { margin-bottom: 0; }
td.actions .btn, td.actions form { margin: 2px; }
a { color: var(--blue); }
a.agentlink { color: var(--text); font-weight: 700; text-decoration: none; }

/* Badges */
.badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.pending { background: var(--amber-d); color: var(--amber); }
.badge.submitted { background: var(--blue-d); color: var(--blue); }
.badge.approved { background: var(--green-d); color: var(--green); }
.badge.delivered { background: #1e293b; color: var(--muted); border: 1px solid var(--border); }
.badge.partial { background: var(--blue-d); color: var(--blue); }
.badge.paid { background: var(--green-d); color: var(--green); }
.badge.normal { background: #1e293b; color: var(--muted); border: 1px solid var(--border); }
.badge.urgent { background: var(--amber-d); color: #fdba74; }
.badge.special { background: #2e1065; color: #c4b5fd; }

/* Alerts & empty */
.alert { padding: 13px 16px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; font-weight: 600; }
.alert.ok { background: var(--green-d); color: var(--green); border: 1px solid rgba(34,197,94,.3); }
.alert.err { background: var(--red-d); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.empty { text-align: center; color: var(--muted); padding: 36px 20px; background: var(--card);
  border: 1px dashed var(--border); border-radius: var(--radius); margin-bottom: 16px; }

/* Login */
.login-box { max-width: 380px; margin: 12vh auto 0; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 26px; text-align: center; box-shadow: var(--shadow); }
.login-box h1 { font-size: 28px; margin: 0 0 6px; font-weight: 800;
  background: linear-gradient(135deg, #fff, #93c5fd); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-box p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login-box .frm { background: none; border: 0; padding: 0; box-shadow: none; text-align: left; }

/* ============ MOBILE ============ */
@media (max-width: 640px) {
  body { font-size: 14px; padding-bottom: 84px; }
  .wrap { padding: 10px 10px; }
  .top h1 { font-size: 19px; }

  /* Bottom nav bar (app-like) */
  .nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: rgba(15,21,36,.96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); margin: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    display: flex; justify-content: space-around; gap: 0; }
  .nav a { flex: 1; text-align: center; padding: 9px 2px; font-size: 11px; border-radius: 8px;
    display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .nav a::first-letter { font-size: 17px; }
  .nav a.active { background: rgba(34,197,94,.15); box-shadow: none; color: var(--green); }

  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 12px; }
  .card .val { font-size: 19px; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  h2 { font-size: 17px; }
  .hide-m { display: none !important; }

  /* Tables → cards */
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  table { background: none; border: 0; box-shadow: none; overflow: visible; }
  tbody tr { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px; padding: 6px 14px; box-shadow: var(--shadow); }
  td { border: 0; padding: 7px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  td::before { content: attr(data-label); font-size: 12px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .4px; font-weight: 700; flex-shrink: 0; }
  td.actions { justify-content: flex-end; }
  td.actions::before { display: none; }
  td:empty { display: none; }
}

/* Date inputs — dark calendar */
.frm input[type="date"]::-webkit-calendar-picker-indicator,
.searchbar input[type="month"]::-webkit-calendar-picker-indicator {
  filter: invert(.7) sepia(1) saturate(3) hue-rotate(90deg);
  cursor: pointer; opacity: .85; padding: 4px;
}

/* Custom modal */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(4,7,14,.7);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal { background: linear-gradient(160deg, var(--card2), var(--card)); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px; max-width: 360px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); transform: scale(.92) translateY(10px); transition: transform .2s; }
.modal-overlay.show .modal { transform: scale(1) translateY(0); }
.modal .icon { font-size: 44px; margin-bottom: 12px; display: block; }
.modal .msg { font-size: 16px; font-weight: 600; margin-bottom: 22px; line-height: 1.5; }
.modal .row { display: flex; gap: 10px; }
.modal .row .btn { flex: 1; margin: 0; }
.modal.danger .icon { filter: drop-shadow(0 0 12px rgba(239,68,68,.5)); }
.modal.success .icon { filter: drop-shadow(0 0 12px rgba(34,197,94,.5)); }

/* Actions column — compact, wraps gracefully */
td.actions { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; align-items: center; }
td.actions .btn, td.actions form { margin: 0; }
td.actions .btn.small { padding: 7px 11px; font-size: 12px; min-height: 34px; }
@media (max-width: 640px) {
  td.actions { justify-content: flex-start; }
}

/* Prevent horizontal page scroll from long content */
html, body { overflow-x: hidden; }
td { overflow-wrap: break-word; word-break: break-word; }
td .doc-name { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
