:root {
  --bg: #f2f4f7; --card: #fff; --ink: #17202e; --muted: #667085; --line: #dfe3ea;
  --brand: #14324f; --accent: #b8892d; --pos: #0b7a46; --neg: #b42318; --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 "Segoe UI", Tahoma, Arial, sans-serif; }
a { color: #175c99; text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
small { color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--brand); color: #fff; }
.topbar a, .topbar small { color: #fff; }
.topbar form { margin: 0; }
.brand { color: #f1d9a2; font-size: 1.1rem; }
.spacer { flex: 1; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--ink); }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand); color: #fff; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.narrow { max-width: 640px; }
.login { max-width: 380px; margin: 10vh auto; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }

.btn { display: inline-block; padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--neg); border-color: #f1b8b3; }
.btn.small { padding: 2px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }

input, select { width: 100%; padding: 9px 10px; border: 1px solid #c8ced8; border-radius: 8px; font: inherit; background: #fff; color: inherit; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.short { max-width: 140px; }
input[type="checkbox"] { width: auto; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; margin-bottom: 3px; color: var(--muted); font-size: .9rem; }
.check { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 10px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.filters input, .filters select { width: auto; }
.filters .check { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { background: #eaf1f8; font-weight: 600; font-size: .9rem; white-space: nowrap; }
tfoot td { font-weight: 700; background: #faf6ec; }
table.compact th, table.compact td { padding: 4px 8px; font-size: .9rem; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
td form { margin: 0; }
.scroll { overflow-x: auto; }
tr.voided td { text-decoration: line-through; color: var(--muted); }
tr.inactive td { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 20px; }
td.pos, .stat.pos strong { color: var(--pos); }
td.neg, .stat.neg strong { color: var(--neg); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #e3f5ea; color: #075e36; border: 1px solid #b7e1c8; }
.flash.error { background: #fdecea; color: var(--neg); border-color: #f5c2bd; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat strong { display: block; font-size: 1.35rem; text-align: right; }
.stat.big { border: 2px solid var(--accent); background: #fffaf0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; color: var(--ink); }
.chip.off { opacity: .45; text-decoration: line-through; }

.statement-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.print-only { display: none; }

/* شاشة المشاريع */
.pos-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.pos-bar input { flex: 1; min-width: 220px; font-size: 1.1rem; }
.segmented { display: flex; border: 1px solid var(--brand); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: #fff; padding: 8px 16px; font: inherit; cursor: pointer; }
.segmented button.on { background: var(--brand); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 3px; min-height: 160px; padding: 14px; text-align: right; font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-top: 6px solid var(--brand); border-radius: 14px; cursor: pointer; box-shadow: 0 1px 3px rgba(16, 24, 40, .08); transition: transform .1s, box-shadow .1s; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(16, 24, 40, .14); }
.tile:active { transform: scale(.97); }
.tile.paused { border-top-color: var(--accent); }
.tile.done { border-top-color: #98a2b3; }
.tile-code { font-size: 1.6rem; font-weight: 700; color: var(--brand); }
.tile-client { font-weight: 600; }
.tile-name, .tile-line { color: var(--muted); font-size: .9rem; }
.tile-due { margin-top: auto; padding: 4px 8px; border-radius: 8px; font-weight: 700; text-align: center; }
.tile-due.neg { background: #fdecea; color: var(--neg); }
.tile-due.pos { background: #e3f5ea; color: var(--pos); }
.tiles .empty { grid-column: 1 / -1; }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; justify-content: center; align-items: flex-start; padding: 20px; background: rgba(16, 24, 40, .55); overflow: auto; }
.overlay.top { z-index: 30; }
.sheet { width: min(900px, 100%); background: var(--bg); border-radius: 16px; padding: 18px; }
.small-sheet { width: min(620px, 100%); background: #fff; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.sheet-head h2, .sheet-head p { margin: 0; }
.sheet table { background: #fff; border-radius: 8px; }
.close { border: 0; background: #e7eaf0; border-radius: 50%; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer; flex: none; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.action { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 96px; padding: 10px; border: 0; border-radius: 14px; background: var(--brand); color: #fff; font: inherit; font-weight: 600; text-align: center; cursor: pointer; }
.action:active { transform: scale(.97); }
.action .icon { font-size: 1.6rem; }
.action.expense { background: var(--neg); }
.action.payment { background: var(--pos); }
.action.fee { background: var(--accent); }
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.small-sheet > label { display: block; margin: 12px 0 5px; font-weight: 600; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { min-height: 42px; padding: 6px 14px; border: 1px solid #c8ced8; border-radius: 10px; background: #fff; font: inherit; cursor: pointer; }
.choices button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.choices.items { max-height: 190px; overflow: auto; margin-top: 6px; padding: 2px; }
input.amount { font-size: 2rem; text-align: center; font-weight: 700; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.numpad button { min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 1.25rem; cursor: pointer; }
.numpad button:active { background: #dbe3ee; }
.row { display: grid; grid-template-columns: 180px 1fr; gap: 8px; margin-top: 14px; }
.save-row { display: flex; gap: 8px; margin-top: 14px; position: sticky; bottom: 0; background: #fff; padding: 8px 0; }
.save-row .btn { flex: 1; padding: 14px; font-size: 1.1rem; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 12px 22px; border-radius: 10px; background: var(--pos); color: #fff; font-weight: 600; max-width: 92%; }
.toast.error { background: var(--neg); }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: block; }
  .nav { display: none; flex-direction: column; }
  .nav.open { display: flex; }
}
@media (max-width: 600px) {
  main { padding: 10px; }
  .card { padding: 12px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overlay { padding: 0; }
  .sheet { min-height: 100%; border-radius: 0; padding: 14px; }
  .row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat strong { font-size: 1.1rem; }
}
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  main { max-width: none; padding: 0; }
  .no-print, .flash { display: none !important; }
  .print-only { display: block; }
  .card { border: 0; padding: 0; }
  .grid-2 { display: block; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .stat strong { font-size: 13px; }
  th, tfoot td, .stat.big { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  th, td { border: 1px solid #888; }
  table.compact th, table.compact td { padding: 2px 5px; font-size: 10.5px; }
  tr { break-inside: avoid; }
  a { color: inherit; }
}
