/* ---------- الثيمات: كل ثيم يغير المتغيرات فقط ---------- */
:root {
  --bg: #f2f4f7; --card: #fff; --ink: #17202e; --muted: #667085; --line: #dfe3ea; --input-line: #c8ced8;
  --brand: #14324f; --on-brand: #fff; --heading: #14324f; --link: #175c99; --brand-name: #f1d9a2;
  --accent: #b8892d; --on-accent: #fff; --pos: #0b7a46; --neg: #b42318; --on-pos: #fff; --on-neg: #fff;
  --soft-pos: #e3f5ea; --soft-neg: #fdecea; --th: #eaf1f8; --foot: #faf6ec; --highlight: #fffaf0; --key: #f2f4f7;
  --radius: 12px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b; --card: #182029; --ink: #e6ebf2; --muted: #98a5b6; --line: #2b3644; --input-line: #3b485a;
  --brand: #2f6fb3; --on-brand: #fff; --heading: #8cc2f5; --link: #8cc2f5; --brand-name: #fff;
  --accent: #d9a441; --on-accent: #17202e; --pos: #4ccf8d; --neg: #ff8178; --on-pos: #07281a; --on-neg: #33070a;
  --soft-pos: #12362a; --soft-neg: #3d1c1d; --th: #212c39; --foot: #29281f; --highlight: #2a2619; --key: #222c38;
}
[data-theme="gold"] {
  color-scheme: dark;
  --bg: #0c0c0c; --card: #171615; --ink: #f1ece1; --muted: #a79f8e; --line: #332f27; --input-line: #4a4436;
  --brand: #c8a24a; --on-brand: #14110a; --heading: #e0bf6c; --link: #e0bf6c; --brand-name: #14110a;
  --accent: #8f7330; --on-accent: #fff; --pos: #57c98a; --neg: #ff7f70; --on-pos: #07281a; --on-neg: #33070a;
  --soft-pos: #163325; --soft-neg: #3b1d19; --th: #24211a; --foot: #282318; --highlight: #27210f; --key: #23211d;
}
[data-theme="emerald"] {
  --bg: #eff6f2; --line: #d5e5dc; --brand: #0d5c46; --heading: #0d5c46; --link: #0b6e53; --brand-name: #ffe3a3;
  --accent: #b7791f; --th: #e2f0e9; --key: #eff6f2;
}
[data-theme="ocean"] {
  --bg: #eef6fd; --line: #d3e4f3; --brand: #0b6bcb; --heading: #0a559f; --link: #0a60b6; --brand-name: #fff;
  --accent: #c2700a; --th: #e1effb; --key: #eef6fd;
}
[data-theme="wine"] {
  --bg: #f8f1f3; --line: #ead9de; --brand: #6d1f37; --heading: #6d1f37; --link: #8a2b49; --brand-name: #f5d8a0;
  --accent: #a8741f; --th: #f4e5e9; --key: #f8f1f3;
}
[data-theme="sand"] {
  --bg: #f5efe4; --card: #fffdf8; --ink: #2f271b; --muted: #756a57; --line: #e4d9c5; --input-line: #cfc0a4;
  --brand: #7a5a2f; --heading: #6a4d26; --link: #7a5220; --brand-name: #fff1cf;
  --accent: #3f6f66; --th: #efe5d1; --foot: #f3ead6; --highlight: #fbf3df; --key: #f5efe4;
}

* { 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: var(--link); 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: var(--on-brand); }
.topbar a, .topbar small { color: var(--on-brand); }
.topbar form { margin: 0; }
.theme-form select { width: auto; max-width: 170px; padding: 3px 8px; font-size: .85rem; background: var(--card); color: var(--ink); }
.brand { color: var(--brand-name); font-size: 1.1rem; }
.spacer { flex: 1; }
.menu-toggle { display: none; background: none; border: 0; color: var(--on-brand); font-size: 1.4rem; cursor: pointer; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 16px; background: var(--card); 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: var(--on-brand); }

.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; }
/* خلفية بيضاء حتى يظهر الشعار بوضوح في الثيمات الداكنة */
.login-logo { display: block; max-width: 220px; max-height: 140px; margin: 0 auto 16px; padding: 8px; background: #fff; border-radius: var(--radius); }
.login-logo + h1 { text-align: center; }
.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: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--heading); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.danger { color: var(--neg); border-color: var(--neg); }
.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 var(--input-line); border-radius: 8px; font: inherit; background: var(--card); color: var(--ink); }
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; }
.logo-preview { max-width: 180px; max-height: 90px; }

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: var(--th); font-weight: 600; font-size: .9rem; white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--foot); }
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: var(--soft-pos); color: var(--pos); border: 1px solid var(--pos); }
.flash.error { background: var(--soft-neg); color: var(--neg); border-color: var(--neg); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); 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: var(--highlight); }

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

.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; width: auto; font-size: 1.1rem; }
.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--brand); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: var(--card); color: var(--ink); padding: 8px 16px; font: inherit; cursor: pointer; }
.segmented button.on { background: var(--brand); color: var(--on-brand); }
.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: var(--ink); background: var(--card); 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, .18); }
.tile:active { transform: scale(.97); }
.tile.person { align-items: center; text-align: center; }
.avatar { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, .22); border: 2px solid rgba(255, 255, 255, .7); font-size: 1.5rem; font-weight: 700; }
.tile-code { font-size: 1.6rem; font-weight: 700; color: var(--heading); }
.tile-client { font-weight: 600; }
.tile-name, .tile-line { color: var(--muted); font-size: .9rem; }
.tile-tag { align-self: flex-start; padding: 0 10px; border-radius: 20px; background: rgba(0, 0, 0, .28); font-size: .78rem; }
.tile.person .tile-tag { align-self: center; }
.tile-due { align-self: stretch; margin-top: auto; padding: 4px 8px; border-radius: 8px; font-weight: 700; text-align: center; background: rgba(255, 255, 255, .94); }
.tile-due.neg { color: #a3160c; }
.tile-due.pos { color: #07643a; }

/* ---------- ألوان الأزرار: ثابتة في كل الثيمات ونصها أبيض ---------- */
.color-0 { --c1: #4f46e5; --c2: #312e81; }
.color-1 { --c1: #0f8f86; --c2: #115e59; }
.color-2 { --c1: #e11d5b; --c2: #881337; }
.color-3 { --c1: #c2650a; --c2: #7c2d12; }
.color-4 { --c1: #8b3fe0; --c2: #4c1d95; }
.color-5 { --c1: #0b7fc4; --c2: #0c4a6e; }
.color-6 { --c1: #0f9658; --c2: #065f46; }
.color-7 { --c1: #c026a8; --c2: #701a75; }
.color-8 { --c1: #dc3a2c; --c2: #7f1d1d; }
.color-9 { --c1: #2563eb; --c2: #1e3a8a; }
.color-10 { --c1: #5c8a10; --c2: #365314; }
.color-11 { --c1: #52667f; --c2: #1e293b; }
.tile[class*="color-"] { position: relative; overflow: hidden; border: 0; color: #fff; background: linear-gradient(140deg, var(--c1), var(--c2)); box-shadow: 0 4px 12px rgba(16, 24, 40, .22); }
.tile[class*="color-"]::after { content: ""; position: absolute; inset-inline-end: -36px; top: -36px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255, 255, 255, .12); pointer-events: none; }
.tile[class*="color-"] .tile-code, .tile[class*="color-"] .tile-name, .tile[class*="color-"] .tile-line { color: #fff; }
.tile[class*="color-"] .tile-name, .tile[class*="color-"] .tile-line { opacity: .9; }
.tile[class*="color-"]:hover { filter: brightness(1.08); box-shadow: 0 10px 22px rgba(16, 24, 40, .32); }
.tile.paused { filter: saturate(.65); }
.tile.done { filter: saturate(.25); }
.tiles .empty { grid-column: 1 / -1; }
.filters input.project-search { flex: 1; min-width: 260px; }
td.report-links .btn { margin-bottom: 4px; }
.tiles.reports { margin-bottom: 18px; }
.tiles.reports .tile { min-height: 90px; justify-content: center; }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; justify-content: center; align-items: flex-start; padding: 20px; background: rgba(8, 12, 20, .6); overflow: auto; }
.overlay.top { z-index: 30; }
.sheet { width: min(900px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.small-sheet { width: min(620px, 100%); background: var(--card); }
.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: var(--card); border-radius: 8px; }
.close { border: 0; background: var(--key); color: var(--ink); 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: var(--on-brand); font: inherit; font-weight: 600; text-align: center; cursor: pointer; }
.action:active { transform: scale(.97); }
.action .icon { font-size: 1.6rem; }
.action[class*="a-"] { color: #fff; background: linear-gradient(140deg, var(--c1), var(--c2)); box-shadow: 0 3px 8px rgba(16, 24, 40, .2); }
.action:hover { filter: brightness(1.08); }
.a-red { --c1: #dc3a2c; --c2: #8f1d14; }
.a-green { --c1: #0f9658; --c2: #065f3a; }
.a-gold { --c1: #bd8613; --c2: #7a5207; }
.a-indigo { --c1: #4f46e5; --c2: #312e81; }
.a-purple { --c1: #8b3fe0; --c2: #4c1d95; }
.a-slate { --c1: #52667f; --c2: #29374b; }
.a-teal { --c1: #0f8f86; --c2: #115e59; }
.a-cyan { --c1: #0b7fc4; --c2: #0c4a6e; }
.a-orange { --c1: #d4620c; --c2: #8a3308; }
.a-pink { --c1: #d02a86; --c2: #831853; }
.choices.big button { flex: 1; min-height: 64px; font-size: 1.15rem; }
.salary-stats { margin-top: 12px; }
.badge { display: inline-block; padding: 0 10px; border-radius: 20px; background: var(--key); font-size: .8rem; white-space: nowrap; }
.badge.ok { background: var(--soft-pos); color: var(--pos); }
.badge.edited { background: var(--highlight); border: 1px solid var(--accent); }

/* ---------- الحضور ---------- */
.attendance-list { display: grid; gap: 8px; margin: 12px 0; }
.attendance-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 12px; color: #fff; background: linear-gradient(140deg, var(--c1), var(--c2)); }
.who span { display: block; font-size: .85rem; opacity: .9; }
.who strong { display: block; }
.marks { display: flex; flex-wrap: wrap; gap: 6px; }
.mark input { position: absolute; opacity: 0; width: 1px; }
.mark span { display: block; min-width: 82px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, .18); text-align: center; cursor: pointer; font-weight: 600; }
.mark input:checked + span { background: #fff; color: #17202e; }
.mark.m100 input:checked + span { color: #07643a; }
.mark.m0 input:checked + span { color: #a3160c; }
.mark.m50 input:checked + span { color: #8a5a00; }
.mark input:focus-visible + span { outline: 3px solid #ffd76a; }
.month-grid th, .month-grid td { text-align: center; padding: 3px 4px; }
.month-grid td:first-child { text-align: right; white-space: nowrap; }
.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; }
.hint { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0; color: var(--muted); }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { min-height: 42px; padding: 6px 14px; border: 1px solid var(--input-line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
.choices button.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.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(--key); color: var(--ink); font-size: 1.25rem; cursor: pointer; }
.numpad button:active { background: var(--th); }
.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: var(--card); 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: var(--on-pos); font-weight: 600; max-width: 92%; }
.toast.error { background: var(--neg); color: var(--on-neg); }

/* ---------- التقرير الختامي: ورقة بيضاء ثابتة الألوان في كل الثيمات ---------- */
.report-sheet { background: #fff; color: #000; border-radius: var(--radius); padding: 18px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.report-sheet th, .report-sheet td { border: 1px solid #222; text-align: center; vertical-align: middle; color: #000; padding: 4px 6px; }
.report-title { width: fit-content; min-width: 300px; margin: 0 0 4px; padding: 6px 24px; background: #e2efda; border: 2px solid #222; font-size: 1.5rem; font-weight: 700; text-align: center; }
.report-head { margin-bottom: 14px; }
.report-head th { background: #fff2cc; width: 12%; }
.report-head td { font-weight: 700; }
.report-head td.logo { width: 14%; }
.report-head img { display: block; max-width: 130px; max-height: 80px; margin: 0 auto; }
.report-net { margin-bottom: 14px; padding: 8px; border: 2px solid #222; background: #fff2cc; text-align: center; font-size: 1.1rem; }
.report-lines th { background: #ddebf7; }
.report-lines td { font-size: .9rem; white-space: nowrap; }
.report-foot { margin: 10px 0 0; font-size: .85rem; text-align: center; color: #444; }

@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; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .theme-form select { max-width: 110px; }
  .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; }
  .report-sheet { padding: 8px; overflow-x: auto; }
}
@media print {
  @page { size: A4; margin: 10mm; }
  /* الطباعة فاتحة دائماً مهما كان الثيم */
  html[data-theme] {
    color-scheme: light;
    --bg: #fff; --card: #fff; --ink: #000; --muted: #444; --line: #bbb; --heading: #000; --link: #000;
    --pos: #0b7a46; --neg: #b42318; --th: #eaf1f8; --foot: #faf6ec; --highlight: #fffaf0;
  }
  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; }
  .scroll { overflow: visible; }
  tr { break-inside: avoid; }
  .report-sheet { padding: 0; border-radius: 0; }
  .report-title { font-size: 18px; }
  .report-sheet th, .report-sheet td { padding: 2px 4px; font-size: 10.5px; }
}
