:root {
  --bg: #f4f6fb; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --primary: #4f46e5; --primary-2: #4338ca; --danger: #dc2626; --success: #059669; --sidebar: #111827;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Tajawal', Tahoma, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; display: flex; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; flex: 1; }
h2 { font-size: 17px; margin: 0 0 14px; display: flex; justify-content: space-between; align-items: center; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.text-danger { color: var(--danger) !important; font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

/* ---------- Sidebar ---------- */
.sidebar { width: 240px; background: var(--sidebar); color: #e5e7eb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { font-weight: 700; font-size: 17px; padding: 22px 20px; border-bottom: 1px solid #1f2937; }
.brand.big { font-size: 22px; text-align: center; border: 0; padding: 0 0 20px; color: var(--text); }
.sidebar nav { flex: 1; padding: 12px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #d1d5db; padding: 11px 14px; border-radius: 10px; margin-bottom: 4px; }
.sidebar nav a:hover { background: #1f2937; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .pill { margin-inline-start: auto; }
.me { padding: 16px 20px; border-top: 1px solid #1f2937; }
.me small { color: #9ca3af; }
.me-links a { color: #a5b4fc; font-size: 13px; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 24px 28px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.menu-btn { display: none; background: none; border: 0; font-size: 24px; cursor: pointer; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--line); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2.wide-left { grid-template-columns: 1.6fr 1fr; align-items: start; }
.grid-2.wide-left .grid-2 { margin-bottom: 20px; }
.grid-2 + .card, .grid-2 { margin-bottom: 20px; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 16px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 12px; }
input, select, textarea { font: inherit; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 9px; background: #fff; width: 100%; color: inherit; }
input[type=color] { padding: 2px; height: 38px; width: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 14px; }
label input, label select, label textarea { margin-top: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; }
.form.narrow { max-width: 460px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form h2 { width: 100%; }
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 150px; }
.inline-form input[type=color] { flex: 0; min-width: 60px; }
.w-sm { width: 70px; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert.danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.pill { display: inline-block; min-width: 22px; text-align: center; padding: 1px 7px; border-radius: 20px; font-size: 12px; background: #e5e7eb; color: #374151; }
.pill.danger { background: var(--danger); color: #fff; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { margin: 0; }
.stat b { display: block; font-size: 28px; margin: 6px 0; }
.stat span { font-size: 13px; color: var(--success); }

.bar-row { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 10px; padding: 7px 0; color: inherit; }
.bar { height: 10px; background: #f3f4f6; border-radius: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 10px; min-width: 2px; }
.link { font-size: 13px; font-weight: 500; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); margin-bottom: 8px; }
.list li small { display: block; }
.list li.late, .followup.late { border-color: #fecaca; background: #fef2f2; }

.timeline { list-style: none; margin: 0; padding: 0 16px 0 0; border-right: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 14px 16px 0; }
.timeline li::before { content: ''; position: absolute; right: -23px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: #c7d2fe; border: 2px solid #fff; }
.timeline li small { display: block; margin-top: 2px; }
.timeline li.act-stage::before { background: var(--primary); }
.timeline li.act-done::before { background: var(--success); }
.timeline li.act-note::before { background: #f59e0b; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-size: 13px; color: var(--muted); font-weight: 500; padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 10px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tr:hover td { background: #fafafa; }
tr.row-late td:first-child { color: var(--danger); font-weight: 700; }
tr.inactive { opacity: .5; }
.actions { position: relative; display: flex; gap: 6px; align-items: center; }
.actions form { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; }
.filters input[type=search] { flex: 2; min-width: 220px; }
.filters select { flex: 1; min-width: 140px; width: auto; }
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.pagination a { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); color: inherit; }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.inline-done { display: flex; gap: 6px; }
.inline-done input { min-width: 130px; padding: 5px 9px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.tabs a { padding: 9px 16px; border-radius: 9px; background: #fff; border: 1px solid var(--line); color: inherit; }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs a.has-late:not(.active) { border-color: #fecaca; color: var(--danger); }
.tab-filter { margin-inline-start: auto; }

/* ---------- Client page ---------- */
.stepper { display: flex; gap: 4px; overflow-x: auto; }
.step { flex: 1; margin: 0; }
.step button { width: 100%; padding: 12px 8px; border: 0; background: #f3f4f6; color: #4b5563; font: inherit; font-weight: 500; cursor: pointer; clip-path: polygon(100% 0, 90% 50%, 100% 100%, 10% 100%, 0 50%, 10% 0); white-space: nowrap; min-width: 100px; }
.step:first-child button { clip-path: polygon(100% 0, 100% 100%, 10% 100%, 0 50%, 10% 0); }
.step button:hover { background: color-mix(in srgb, var(--c) 25%, #fff); }
.step.current button { background: var(--c); color: #fff; font-weight: 700; }
.info { display: grid; grid-template-columns: 130px 1fr; gap: 10px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.notes { background: #fffbeb; padding: 12px; border-radius: 9px; border: 1px solid #fde68a; }
.quick { display: flex; gap: 8px; margin-top: 14px; }
.followup { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.followup summary { cursor: pointer; }
.followup form { margin-top: 14px; }
details.mini summary { list-style: none; }
details.mini[open] form { position: absolute; left: 30px; background: #fff; padding: 14px; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 10; display: grid; gap: 8px; width: 260px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 16px; align-items: flex-start; }
.column { min-width: 260px; width: 260px; background: #eef0f5; border-radius: var(--radius); border-top: 4px solid var(--c); }
.column.over { background: color-mix(in srgb, var(--c) 15%, #eef0f5); }
.col-head { padding: 12px 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col-head small { width: 100%; }
.col-body { padding: 0 10px 10px; min-height: 120px; }
.kcard { display: block; background: #fff; border-radius: 10px; padding: 12px; margin-bottom: 8px; color: inherit; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: grab; }
.kcard small { display: block; }
.kcard.dragging { opacity: .4; }
.kmeta { display: flex; justify-content: space-between; font-size: 13px; margin-top: 8px; color: var(--muted); }

/* ---------- Login ---------- */
.login-page { align-items: center; justify-content: center; background: linear-gradient(135deg, #4f46e5, #111827); }
.login-box { width: 380px; max-width: 92vw; padding: 32px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; right: -260px; z-index: 50; transition: right .2s; }
  .sidebar.open { right: 0; }
  .menu-btn { display: block; }
  .main { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat b { font-size: 20px; }
  .topbar h1 { font-size: 18px; }
}

/* ---------- Invoices ---------- */
.sub-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 16px; }
.seg { display: flex; gap: 6px; margin-bottom: 14px; }
.seg label { flex: 1; margin: 0; display: flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 9px; padding: 9px; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--primary); background: #eef2ff; color: var(--primary); }
.seg input, label.check input { width: auto; margin: 0; }
label.check { display: flex; align-items: center; gap: 8px; }
.form-grid.tight { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.paid-toggle { font: inherit; font-size: 13px; border: 1px solid #fed7aa; background: #fff7ed; color: #c2410c; border-radius: 20px; padding: 3px 11px; cursor: pointer; white-space: nowrap; }
.paid-toggle.is-paid { border-color: #a7f3d0; background: #ecfdf5; color: var(--success); }
tfoot .total-row td { font-weight: 700; border-top: 2px solid var(--line); background: #f9fafb; }
.month-row { grid-template-columns: 110px 1fr auto; cursor: default; }
.nw { white-space: nowrap; }
