/* ==========================================================
   School Project Tracker — โรงเรียนโรตารี่กรุงเทพ
   โทนสี: น้ำเงิน / ฟ้าอ่อน
   ========================================================== */
:root {
  --navy: #0b2f6b;
  --primary: #1d5fd6;
  --primary-600: #1a4fb8;
  --primary-50: #eaf2ff;
  --sky: #0ea5e9;
  --sky-100: #e0f2fe;
  --bg: #eef5fd;
  --bg-2: #f6faff;
  --card: #ffffff;
  --text: #10284a;
  --text-2: #3a5275;
  --muted: #6b7f99;
  --border: #dbe6f4;
  --track: #e5eef9;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 74, .04), 0 6px 20px rgba(29, 95, 214, .07);
  --shadow-lg: 0 12px 40px rgba(16, 40, 74, .14);
  --font: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  --font-head: 'Prompt', 'Sarabun', 'Noto Sans Thai', sans-serif;
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.3; margin: 0; color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
img { max-width: 100%; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; background: var(--primary-50); color: var(--primary-600); padding: 1px 6px; border-radius: 6px; }
small { font-size: .86em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.d-block { display: block; }
.pad { padding: 8px 4px; }
.neg { color: var(--red) !important; }
.pos { color: var(--green); }
.icon { flex-shrink: 0; vertical-align: middle; }
[hidden] { display: none !important; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: linear-gradient(180deg, #0b2f6b 0%, #123f8f 55%, #1856c4 100%);
  color: #dbe9ff; display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(11, 47, 107, .18);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 18px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand img { width: 52px; height: 52px; border-radius: 50%; background: #fff; padding: 2px; box-shadow: 0 0 0 3px rgba(125, 211, 252, .35); }
.brand span { display: flex; flex-direction: column; min-width: 0; }
.brand b { font-family: var(--font-head); font-size: 1.02rem; font-weight: 600; line-height: 1.25; }
.brand small { color: #9cc7ff; font-size: .78rem; letter-spacing: .3px; }
.brand:hover { color: #fff; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; color: #87aee8; padding: 16px 12px 6px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0; border-radius: 10px; color: #d4e4ff; font-weight: 500; transition: background .15s, color .15s; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: #fff; color: var(--primary); box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.nav-link.active .icon { color: var(--primary); }
.sidebar-foot { padding: 14px 18px 20px; }
.year-chip { display: inline-block; background: rgba(125, 211, 252, .16); color: #bfe6ff; border: 1px solid rgba(125, 211, 252, .3); border-radius: 999px; padding: 4px 12px; font-size: .82rem; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: rgba(255,255,255,.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.topbar h1 { font-size: 1.28rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-link { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary-50); color: var(--primary); }
.menu-btn { display: none !important; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta b { font-size: .92rem; font-weight: 600; }
.content { padding: 24px 28px 36px; flex: 1; }
.foot { padding: 16px 28px 22px; color: var(--muted); font-size: .82rem; }

/* ---------------- Avatars & tags ---------------- */
.avatar { width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; font-family: var(--font-head); font-weight: 600; color: #fff; flex-shrink: 0; background: var(--primary); }
.avatar-teacher { background: linear-gradient(135deg, #22c55e, #15803d); }
.avatar-executive { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.avatar-admin { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.role-tag { display: inline-block; font-size: .74rem; font-weight: 600; padding: 1px 9px; border-radius: 999px; }
.role-tag-teacher { background: #dcfce7; color: #15803d; }
.role-tag-executive { background: #dbeafe; color: #1d4ed8; }
.role-tag-admin { background: #ede9fe; color: #6d28d9; }
.tag-mine { display: inline-block; font-size: .72rem; font-weight: 600; background: linear-gradient(90deg, #fde68a, #fcd34d); color: #854d0e; padding: 0 8px; border-radius: 999px; }
.tag-mine.corner { position: absolute; top: -8px; right: 14px; }
.code { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: 9px; background: var(--primary-50); color: var(--primary); font-family: var(--font-head); font-weight: 600; font-size: .9rem; }
.code.big { min-width: auto; padding: 0 12px; height: 28px; font-size: .85rem; }
.dept-dot { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--text-2); }
.dept-dot::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--primary)); }
.pill { display: inline-block; background: var(--primary-50); color: var(--primary-600); padding: 1px 10px; border-radius: 999px; font-size: .8rem; }
.pill-red { background: #fee2e2; color: #b91c1c; }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-gray { background: #eef2f7; color: #64748b; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-red-outline { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
.badge-amber-outline { background: #fff; color: #b45309; border: 1px solid #fcd34d; }
.badge-red-outline::before, .badge-amber-outline::before { display: none; }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 11px; padding: 9px 16px; font-family: var(--font-head); font-size: .92rem; font-weight: 500; cursor: pointer; transition: transform .08s, box-shadow .15s, background .15s; white-space: nowrap; text-decoration: none; line-height: 1.2; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, #2b74ec, #1a4fb8); color: #fff; box-shadow: 0 4px 14px rgba(29, 95, 214, .3); }
.btn-primary:hover { color: #fff; box-shadow: 0 6px 18px rgba(29, 95, 214, .4); }
.btn-ghost { background: #fff; color: var(--primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--primary-50); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-sm { padding: 5px 12px; font-size: .84rem; border-radius: 9px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--primary-50); color: var(--primary); }
.icon-btn.danger:hover { background: #fee2e2; color: #dc2626; }
.row-actions { display: flex; align-items: center; gap: 2px; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* ---------------- Cards ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px; }
.card.narrow { max-width: 760px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 1.06rem; display: flex; align-items: center; gap: 8px; }
.card-head h3 .icon { color: var(--primary); }
.sub-title { font-size: .98rem; margin: 22px 0 10px; }
.link { font-size: .9rem; font-weight: 500; }
.stack > .card:last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 20px; align-items: start; }
.grid-2 > .card, .grid-2 > .stack > .card { margin-bottom: 20px; }
.grid-2.wide-left { grid-template-columns: minmax(0,1.5fr) minmax(0,1fr); }
.grid-2 > *, .grid-3 > *, .stack > * { min-width: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 20px; }
.grid-3 > .card { margin-bottom: 20px; }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 0; }

/* ---------------- Stats ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: var(--tint); opacity: .5; }
.stat-ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; color: #fff; background: var(--ic); flex-shrink: 0; box-shadow: 0 6px 16px var(--shadow-c); z-index: 1; }
.stat-card > div:last-child { display: flex; flex-direction: column; z-index: 1; min-width: 0; }
.stat-card small { color: var(--muted); font-weight: 500; }
.stat-card b { font-family: var(--font-head); font-size: 1.6rem; font-weight: 600; line-height: 1.15; letter-spacing: -.3px; }
.stat-card span { color: var(--muted); font-size: .84rem; }
.s-blue { --ic: linear-gradient(135deg, #3b82f6, #1d4ed8); --tint: #dbeafe; --shadow-c: rgba(29, 78, 216, .3); }
.s-sky { --ic: linear-gradient(135deg, #38bdf8, #0284c7); --tint: #e0f2fe; --shadow-c: rgba(2, 132, 199, .3); }
.s-amber { --ic: linear-gradient(135deg, #fbbf24, #f59e0b); --tint: #fef3c7; --shadow-c: rgba(245, 158, 11, .3); }
.s-green { --ic: linear-gradient(135deg, #4ade80, #16a34a); --tint: #dcfce7; --shadow-c: rgba(22, 163, 74, .3); }

/* hero kpi (dashboard) */
.page-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-intro h2 { font-size: 1.3rem; }
.page-intro p { margin: 2px 0 0; }
.page-intro form { display: flex; gap: 10px; }
.hero-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.hk { display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: var(--radius); color: #fff; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hk::after { content: ''; position: absolute; right: -40px; bottom: -60px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.12); }
.hk-num { width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.22); display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 1.3rem; flex-shrink: 0; }
.hk div { display: flex; flex-direction: column; z-index: 1; min-width: 0; }
.hk b { font-family: var(--font-head); font-size: 1.65rem; font-weight: 600; line-height: 1.15; }
.hk small { opacity: .9; }
.hk-1 { background: linear-gradient(135deg, #2563eb, #1e40af); }
.hk-2 { background: linear-gradient(135deg, #0ea5e9, #0369a1); }
.hk-3 { background: linear-gradient(135deg, #f59e0b, #d97706); }
.hk-4 { background: linear-gradient(135deg, #22c55e, #15803d); }

/* project page KPI */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; border-top: 4px solid var(--k); }
.kpi small { color: var(--muted); font-weight: 500; }
.kpi b { font-family: var(--font-head); font-size: 1.7rem; font-weight: 600; color: var(--k); line-height: 1.2; }
.kpi span { color: var(--muted); font-size: .85rem; }
.k-blue { --k: #1d5fd6; } .k-amber { --k: #d97706; } .k-green { --k: #16a34a; } .k-red { --k: #dc2626; }
.k-ring { --k: #0ea5e9; flex-direction: row; align-items: center; gap: 12px; }
.k-ring > div { display: flex; flex-direction: column; }
.k-ring b { color: var(--text); }
.budget-strip { padding: 14px 20px; }
.bs-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: .92rem; flex-wrap: wrap; gap: 6px; }
.bs-head span { color: var(--muted); }
.budget-strip .progress { height: 14px; }

/* ---------------- Progress ---------------- */
.progress { position: relative; height: 9px; background: var(--track); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #38bdf8, #1d5fd6); transition: width .6s ease; }
.progress.warn > span { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.progress.over > span { background: linear-gradient(90deg, #f87171, #dc2626); }
.progress.prog > span { background: linear-gradient(90deg, #4ade80, #16a34a); }
.progress-label { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px; }
td .progress-label { text-align: right; }
.mini-progress { height: 4px; background: var(--track); border-radius: 9px; margin-top: 6px; width: 90px; overflow: hidden; }
.mini-progress span { display: block; height: 100%; background: var(--green); }

/* ---------------- Toolbar / chips ---------------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.search { flex: 1; min-width: 220px; max-width: 420px; position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 12px; color: var(--muted); }
.search input[type=search] { padding-left: 40px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--text-2); font-size: .88rem; font-weight: 500; }
.chip b { background: var(--track); border-radius: 999px; padding: 0 8px; font-size: .78rem; }
.chip:hover { border-color: #b7cdee; color: var(--text); }
.chip.on { color: #fff; border-color: transparent; }
.chip.on b { background: rgba(255,255,255,.25); }
.chip-blue.on { background: var(--primary); } .chip-gray.on { background: #64748b; } .chip-amber.on { background: #f59e0b; } .chip-green.on { background: #16a34a; } .chip-red.on { background: #ef4444; } .chip-purple.on { background: #7c3aed; }
.seg { display: inline-flex; background: var(--track); border-radius: 11px; padding: 3px; }
.seg button, .seg a { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-head); font-size: .88rem; }
.seg button.on, .seg a.on { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ---------------- Forms ---------------- */
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid #cfdcee; border-radius: 11px; padding: 10px 13px; transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #60a5fa; box-shadow: 0 0 0 4px rgba(96, 165, 250, .2); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7f99' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.toolbar select { width: auto; min-width: 170px; }
.select-sm, .input-sm { min-height: 32px; padding: 4px 28px 4px 10px; font-size: .84rem; border-radius: 8px; width: auto; }
.input-sm { width: 70px; padding-right: 8px; }
input[type=color] { width: 44px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: #fff; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: .9rem; color: var(--text-2); }
.req { color: var(--red); font-style: normal; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row.r-3 { grid-template-columns: repeat(3, 1fr); }
.field-row.r-4-1 { grid-template-columns: 4fr 1fr; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; flex-wrap: wrap; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 8px; z-index: 5; }
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }
input[type=range] { width: 100%; accent-color: var(--primary); height: 28px; }
.small-note { font-size: .86rem; margin: -6px 0 10px; }

.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 22px 16px; border: 2px dashed #a9c6ef; border-radius: 14px; background: linear-gradient(180deg, #f5f9ff, #edf5ff); color: var(--primary); cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone:hover, .dropzone.drag { background: #e3efff; border-color: var(--primary); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone small { color: var(--muted); }
.preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 8px; }
.preview figure { margin: 0; position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview figcaption { position: absolute; inset: auto 0 0; background: rgba(0,0,0,.55); color: #fff; font-size: .68rem; padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.remain-hint { font-size: .88rem; margin-top: -6px; min-height: 1em; }
.remain-hint.ok { color: var(--green); } .remain-hint.over { color: var(--red); font-weight: 600; }

.status-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.st-opt { position: relative; cursor: pointer; }
.st-opt input { position: absolute; opacity: 0; }
.st-opt span { display: block; text-align: center; padding: 10px 6px; border-radius: 11px; border: 2px solid var(--border); font-weight: 600; font-size: .88rem; color: var(--muted); transition: all .15s; }
.st-opt input:checked + span { color: #fff; border-color: transparent; }
.st-not_started input:checked + span { background: #64748b; }
.st-in_progress input:checked + span { background: #f59e0b; }
.st-completed input:checked + span { background: #16a34a; }
.st-delayed input:checked + span { background: #ef4444; }
.st-opt input:focus-visible + span { box-shadow: 0 0 0 3px rgba(96,165,250,.4); }
.status-select.st-completed { color: #15803d; border-color: #86efac; background-color: #f0fdf4; }
.status-select.st-in_progress { color: #b45309; border-color: #fcd34d; background-color: #fffbeb; }
.status-select.st-delayed { color: #b91c1c; border-color: #fca5a5; background-color: #fef2f2; }
form.inline { margin: 0; }

/* ---------------- Alerts ---------------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: .94rem; border: 1px solid; }
.alert .icon { margin-top: 2px; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert a { font-weight: 600; text-decoration: underline; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .92rem; }
.table th { text-align: left; font-family: var(--font-head); font-weight: 500; font-size: .82rem; color: var(--muted); background: var(--bg-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th:first-child { border-top-left-radius: 10px; } .table th:last-child { border-top-right-radius: 10px; }
.table td { padding: 12px; border-bottom: 1px solid #edf2f9; vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f7fbff; }
.table tr[data-href] { cursor: pointer; }
.table tfoot td { background: var(--bg-2); border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table.compact td { padding: 9px 10px; }
.w-num { width: 48px; } .w-usage { width: 130px; min-width: 110px; } .w-act { width: 90px; } .w-lvl { width: 90px; } .w-money { width: 140px; } .w-owner { width: 200px; }
.p-name { font-weight: 600; color: var(--text); display: block; line-height: 1.4; }
.p-name:hover { color: var(--primary); }
.p-name.sm { font-weight: 500; font-size: .9rem; }
.p-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: .8rem; color: var(--muted); align-items: center; }
.p-meta .icon { width: 14px; height: 14px; }
.owner { white-space: nowrap; color: var(--text-2); font-size: .88rem; }
tr.inactive { opacity: .55; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell span { display: flex; flex-direction: column; line-height: 1.3; }
.act-table tr.sub td:first-child { padding-left: 34px; position: relative; }
.act-table tr.sub td:first-child::before { content: ''; position: absolute; left: 16px; top: 0; bottom: 50%; width: 10px; border-left: 2px solid var(--border); border-bottom: 2px solid var(--border); border-bottom-left-radius: 6px; }
.act-table tr.parent { background: var(--bg-2); }
.act-table tr.parent .act-name { font-weight: 600; }
.act-table tr.mine { background: #fffbeb; }
.act-editor td { padding: 6px; }
.act-editor tr.sub td:nth-child(2) input { margin-left: 18px; width: calc(100% - 18px); border-left: 3px solid #93c5fd; }
.new-row td { background: #f8fbff; }

/* ---------------- Project cards ---------------- */
.view { display: none; }
body[data-view="table"] .view-table, body:not([data-view]) .view-table { display: block; }
body[data-view="cards"] .view-cards { display: block; }
.p-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.p-card { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 18px; border-radius: 14px; border: 1px solid var(--border); background: #fff; color: var(--text); border-top: 4px solid var(--c); transition: transform .15s, box-shadow .15s; }
.p-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); color: var(--text); }
.p-card-top { display: flex; justify-content: space-between; align-items: center; }
.p-card h3 { font-size: 1rem; line-height: 1.45; min-height: 2.9em; }
.p-card-dept { margin: 0; font-size: .84rem; color: var(--muted); }
.p-card-money { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--bg-2); border-radius: 10px; padding: 10px 12px; }
.p-card-money div { display: flex; flex-direction: column; }
.p-card-money small { color: var(--muted); font-size: .76rem; }
.p-card-money b { font-family: var(--font-head); font-weight: 600; font-size: 1.08rem; }
.p-card-bars { display: grid; grid-template-columns: 80px 1fr; gap: 4px 10px; align-items: center; font-size: .82rem; color: var(--muted); }
.p-card-bars .progress-label { display: none; }

/* ---------------- Project head ---------------- */
.project-head { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; border-left: 6px solid var(--c); background: linear-gradient(100deg, #fff 60%, #f0f7ff); }
.ph-main { flex: 1; min-width: 280px; }
.ph-tags { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.project-head h2 { font-size: 1.38rem; margin-bottom: 8px; }
.ph-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--text-2); font-size: .9rem; }
.ph-meta span { display: inline-flex; align-items: center; gap: 6px; }
.ph-meta .icon { color: var(--primary); }
.ph-actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.seg-text a { font-size: .86rem; padding: 6px 12px; }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 6px; background: var(--track); padding: 4px; border-radius: 13px; margin-bottom: 18px; }
.tabs button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border: 0; background: transparent; border-radius: 10px; font-family: var(--font-head); font-size: .95rem; color: var(--muted); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.update-grid { grid-template-columns: minmax(400px, 0.95fr) minmax(0, 1.35fr); }
.act-table td:first-child { min-width: 230px; }
.update-grid .act-table .owner { white-space: normal; min-width: 110px; }

/* ---------------- Expenses ---------------- */
.expense-list.collapsed .expense:nth-child(n+9) { display: none; }
.show-all { margin-top: 10px; }
.expense-list { display: flex; flex-direction: column; gap: 10px; }
.expense { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 13px; background: #fff; }
.expense:hover { border-color: #bcd3f2; }
.expense-date { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--primary-50); border-radius: 11px; height: 56px; color: var(--primary); }
.expense-date b { font-family: var(--font-head); font-size: 1.25rem; line-height: 1; }
.expense-date small { font-size: .72rem; }
.expense-body h4 { font-size: .98rem; font-weight: 600; }
.expense-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 4px 0 0; font-size: .8rem; color: var(--muted); align-items: center; }
.expense-note { margin: 6px 0 0; font-size: .86rem; color: var(--text-2); }
.expense-amount { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.expense-amount > b { font-family: var(--font-head); font-size: 1.15rem; font-weight: 600; color: var(--text); white-space: nowrap; }
.expense-amount > small { color: var(--muted); font-size: .76rem; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.thumb { display: block; width: 70px; height: 70px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.thumb:hover img { transform: scale(1.06); }
.thumbs.editable .thumb { width: 96px; height: 96px; cursor: pointer; }
.thumbs.editable input { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; accent-color: var(--red); }
.thumbs.editable .rm { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(239,68,68,.55); color: #fff; opacity: 0; transition: opacity .15s; }
.thumbs.editable input:checked ~ .rm { opacity: 1; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery a { position: relative; display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.gallery img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.gallery a:hover img { transform: scale(1.05); }
.gallery span { position: absolute; inset: auto 0 0; padding: 18px 8px 6px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding-bottom: 16px; }
.timeline li::before { content: ''; position: absolute; left: 6px; top: 16px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.tl-dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; box-shadow: 0 0 0 4px #fff, 0 0 0 5px var(--border); }
.tl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.timeline p { margin: 4px 0 2px; font-size: .9rem; }

/* ---------------- Charts ---------------- */
.chart-card { display: flex; flex-direction: column; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: center; }
.donut { flex-shrink: 0; }
.donut-value { font-family: var(--font-head); font-size: 26px; font-weight: 600; fill: var(--text); }
.donut-label { font-size: 12px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 160px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 8px; align-items: center; font-size: .88rem; }
.legend .dot { width: 11px; height: 11px; border-radius: 4px; }
.legend b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend small { color: var(--muted); width: 46px; text-align: right; }
.legend-inline { font-size: .82rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw-budget { background: #dbe8f8; margin-left: 4px; } .sw-spent { background: var(--primary); margin-left: 8px; }
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr auto; gap: 12px; align-items: center; font-size: .88rem; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.bar-track { position: relative; height: 18px; background: #f3f7fc; border-radius: 6px; }
.bar-budget, .bar-spent { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.bar-budget { background: #dbe8f8; }
.bar-spent { top: 4px; bottom: 4px; border-radius: 4px; }
.bar-val { font-size: .8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-val b { color: var(--text); }
.columns { width: 100%; height: auto; }
.columns .grid { stroke: #edf2f9; }
.columns .col { fill: #3b82f6; }
.columns .col:hover { fill: #1d4ed8; }
.columns .col-val { font-size: 11px; fill: var(--text-2); font-weight: 600; }
.columns .col-lbl { font-size: 11px; fill: var(--muted); }
.ring-text { font-family: var(--font-head); font-size: 17px; font-weight: 600; fill: var(--text); }
.perf { display: flex; justify-content: space-around; gap: 10px; flex-wrap: wrap; }
.perf-item { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; font-size: .86rem; color: var(--muted); }
.perf-item b { color: var(--text); }
.perf-alerts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.pa { text-align: center; padding: 8px; border-radius: 10px; font-size: .82rem; }
.pa b { display: block; font-family: var(--font-head); font-size: 1.3rem; line-height: 1.2; }
.pa-red { background: #fef2f2; color: #b91c1c; } .pa-orange { background: #fff7ed; color: #c2410c; } .pa-gray { background: #f1f5f9; color: #475569; }

/* watch list */
.attention { border-color: #fde68a; background: linear-gradient(180deg, #fffdf5, #fff); }
.attention h3 .icon { color: #d97706 !important; }
.watch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.watch { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: #fff; color: var(--text); }
.watch:hover { border-color: #fcd34d; color: var(--text); }
.watch-name { flex: 1; min-width: 0; font-size: .9rem; font-weight: 500; line-height: 1.35; }
.watch-name small { display: block; color: var(--muted); font-weight: 400; }
.watch-why { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* recent */
.recent { list-style: none; margin: 0; padding: 0; }
.recent li + li { border-top: 1px solid #edf2f9; }
.recent a { display: flex; align-items: center; gap: 12px; padding: 10px 2px; color: var(--text); }
.recent img, .recent-ic { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.recent-ic { display: grid; place-items: center; background: var(--primary-50); color: var(--primary); }
.recent-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.recent-body b { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-body small { color: var(--muted); }
.recent-amt { font-family: var(--font-head); font-weight: 600; white-space: nowrap; }

/* empty */
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state.small { padding: 22px 10px; }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); font-size: 30px; }
.empty-state.small .empty-icon { width: 58px; height: 58px; }
.empty-state h2, .empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p { margin: 4px 0 14px; }

/* misc */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.detail-grid h4 { font-size: .92rem; color: var(--primary); margin-bottom: 4px; }
.detail-grid p { margin: 0; }
.kv { list-style: none; padding: 0; margin: 0 0 14px; }
.kv li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.danger-zone { border-color: #fecaca; }
.danger-zone h3 .icon { color: var(--red) !important; }
.logo-edit { display: flex; align-items: center; gap: 16px; }
.logo-edit img { width: 84px; height: 84px; border-radius: 50%; border: 3px solid var(--sky-100); }
.profile-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.profile-top .avatar { width: 60px; height: 60px; font-size: 1.5rem; }
.simple-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.simple-list a { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .92rem; }
.pager { display: flex; gap: 4px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; border: 1px solid var(--border); color: var(--text-2); }
.pager a.on { background: var(--primary); color: #fff; border-color: transparent; }
.export-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.export-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; color: var(--text); box-shadow: var(--shadow); text-align: left; font: inherit; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.export-card .icon { color: var(--primary); background: var(--primary-50); padding: 10px; width: 48px; height: 48px; border-radius: 12px; }
.export-card b { font-family: var(--font-head); font-weight: 600; }
.export-card small { color: var(--muted); }
.export-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); color: var(--text); }
.report-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 2px solid var(--primary-50); }
.report-head img { width: 64px; height: 64px; border-radius: 50%; }
.report-head h2 { font-size: 1.2rem; }
.report-head p { margin: 2px 0 0; color: var(--muted); }
.report-table td { padding: 8px 10px; }
.report-table .group-row td { background: #eef5ff; border-left: 0; color: var(--navy); }
.report-table .group-row td:first-child { box-shadow: inset 4px 0 0 var(--c); }
.report-table .act-row td { font-size: .84rem; color: var(--text-2); }
.report-table .act-row td:nth-child(2) { padding-left: 26px; }
.report-table .act-row.lvl2 td:nth-child(2) { padding-left: 44px; }
.report-table a { color: var(--text); font-weight: 600; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px; text-align: center; }
.signatures p { margin: 6px 0; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8, 20, 45, .9); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; }
.lightbox img { max-width: 100%; max-height: 82vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox-cap { color: #e2ecff; margin-top: 12px; text-align: center; }
.lightbox-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,.12); border: 0; color: #fff; width: 46px; height: 46px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }

/* ==========================================================
   Login
   ========================================================== */
.guest { min-height: 100vh; }
.login-page {
  position: relative; min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; align-items: center; gap: 40px;
  padding: 40px clamp(20px, 6vw, 90px); overflow: hidden;
  background: radial-gradient(1200px 600px at 10% 0%, #cfe6ff 0%, transparent 60%), radial-gradient(900px 600px at 100% 100%, #bfe3ff 0%, transparent 55%), linear-gradient(160deg, #eaf4ff 0%, #d9ecff 100%);
}
.login-bg { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.login-bg span { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .55; z-index: 0; }
.login-bg span:nth-child(1) { width: 420px; height: 420px; left: -120px; bottom: -160px; background: radial-gradient(circle, #7cc4ff, transparent 70%); }
.login-bg span:nth-child(2) { width: 300px; height: 300px; right: 8%; top: -110px; background: radial-gradient(circle, #a5d8ff, transparent 70%); }
.login-bg span:nth-child(3) { width: 180px; height: 180px; left: 46%; top: 12%; background: radial-gradient(circle, #e0f2fe, transparent 70%); }
.login-hero {
  position: relative; z-index: 1; color: #fff; padding: 44px 44px 36px; border-radius: 28px;
  background: linear-gradient(150deg, #0b2f6b 0%, #1450b8 55%, #1f8fe0 100%);
  box-shadow: 0 30px 70px rgba(11, 47, 107, .35); overflow: hidden;
}
.login-hero::before { content: ''; position: absolute; right: -90px; top: -90px; width: 300px; height: 300px; border-radius: 50%; border: 50px solid rgba(255,255,255,.06); }
.login-hero::after { content: ''; position: absolute; left: -60px; bottom: -120px; width: 260px; height: 260px; border-radius: 50%; background: rgba(125, 211, 252, .12); }
.hero-logo { width: 116px; height: 116px; border-radius: 50%; background: #fff; padding: 4px; box-shadow: 0 0 0 6px rgba(255,255,255,.18), 0 12px 30px rgba(0,0,0,.25); position: relative; z-index: 1; }
.login-hero h1 { color: #fff; font-size: clamp(1.6rem, 2.6vw, 2.2rem); margin-top: 18px; position: relative; z-index: 1; }
.hero-en { margin: 2px 0 0; color: #a8d4ff; font-family: var(--font-head); letter-spacing: .5px; position: relative; z-index: 1; }
.hero-divider { width: 64px; height: 4px; border-radius: 9px; background: linear-gradient(90deg, #7dd3fc, #fff); margin: 18px 0; }
.login-hero h2 { color: #fff; font-size: 1.35rem; position: relative; z-index: 1; }
.hero-sub { color: #d6e9ff; margin: 4px 0 18px; position: relative; z-index: 1; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; position: relative; z-index: 1; }
.hero-points li { display: flex; gap: 10px; align-items: center; color: #eaf4ff; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); padding: 9px 14px; border-radius: 12px; font-size: .94rem; }
.hero-points .icon { color: #7dd3fc; }
.hero-aff { margin: 22px 0 0; font-size: .8rem; color: #9cc7ff; position: relative; z-index: 1; }

.login-card { position: relative; z-index: 1; background: rgba(255,255,255,.96); border-radius: 26px; padding: 32px 32px 26px; box-shadow: 0 30px 70px rgba(16, 40, 74, .18); border: 1px solid rgba(255,255,255,.8); max-width: 460px; width: 100%; justify-self: center; }
.login-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.mini-logo { width: 54px; height: 54px; border-radius: 50%; display: none; }
.login-card-head h3 { font-size: 1.5rem; color: var(--navy); }
.login-card-head p { margin: 0; color: var(--muted); }
.field-title { font-weight: 600; color: var(--text-2); margin: 0 0 10px; font-size: .92rem; }
.role-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.role-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px 12px; border-radius: 16px; border: 2px solid var(--border); background: #fff; cursor: pointer; font-family: var(--font-head); font-weight: 500; color: var(--text-2); transition: all .15s; }
.role-tile input { position: absolute; opacity: 0; }
.role-ic { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: var(--rc); background: var(--rbg); transition: all .15s; }
.role-executive { --rc: #1d5fd6; --rbg: #e3eeff; }
.role-teacher { --rc: #16a34a; --rbg: #dcfce7; }
.role-admin { --rc: #7c3aed; --rbg: #ede9fe; }
.role-tile:hover { border-color: var(--rc); }
.role-tile:has(input:checked) { border-color: var(--rc); background: var(--rbg); color: var(--rc); box-shadow: 0 8px 20px -8px var(--rc); }
.role-tile:has(input:checked) .role-ic { background: var(--rc); color: #fff; }
.role-tile:has(input:focus-visible) { box-shadow: 0 0 0 4px rgba(96,165,250,.35); }
.role-picker.compact .role-tile { flex-direction: row; justify-content: center; padding: 8px; }
.role-picker.compact .role-ic { width: 36px; height: 36px; border-radius: 10px; }
.input-icon { position: relative; display: flex; align-items: center; margin-bottom: 12px; }
.input-icon > .icon { position: absolute; left: 14px; color: var(--muted); }
.input-icon input { padding-left: 42px; min-height: 50px; border-radius: 13px; background: #f7faff; }
.pw-toggle { position: absolute; right: 8px; background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.pw-toggle:hover { color: var(--primary); }
.login-card .btn-lg { margin-top: 6px; min-height: 52px; font-size: 1.05rem; border-radius: 13px; }
.login-help { text-align: center; color: var(--muted); font-size: .84rem; margin: 16px 0 0; }

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 .span-2 { grid-column: span 2; }
  .update-grid { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(8, 20, 45, .45); z-index: 35; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid !important; }
  .stat-grid, .hero-kpis, .kpi-row, .export-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2, .grid-2.wide-left { grid-template-columns: minmax(0,1fr); }
  .login-page { grid-template-columns: 1fr; padding-top: 28px; gap: 24px; }
  .login-hero { padding: 30px 26px; }
  .hero-points { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .content { padding: 16px 16px 28px; }
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 1.08rem; }
  .user-meta { display: none; }
  .card { padding: 16px; border-radius: 14px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .grid-3 { grid-template-columns: minmax(0,1fr); }
  .grid-3 .span-2 { grid-column: auto; }
  .stat-grid, .hero-kpis, .kpi-row { gap: 10px; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .page-intro form { width: 100%; }
  .page-intro form select { flex: 1; width: auto; }
  .legend li { grid-template-columns: 12px 1fr auto; }
  .legend small { display: none; }
  .stat-card { padding: 14px; gap: 10px; flex-direction: column; align-items: flex-start; }
  .stat-ic { width: 40px; height: 40px; border-radius: 11px; }
  .stat-card b, .hk b, .kpi b { font-size: 1.22rem; }
  .hk { padding: 14px; }
  .hk-num { display: none; }
  .k-ring .ring { width: 56px; height: 56px; }
  .export-grid { grid-template-columns: 1fr; }
  .field-row, .field-row.r-3, .field-row.r-4-1 { grid-template-columns: 1fr; }
  .status-picker { grid-template-columns: 1fr 1fr; }
  .toolbar select { flex: 1; min-width: 0; }
  .search { min-width: 100%; }
  .toolbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .expense { grid-template-columns: 46px 1fr; }
  .expense-date { height: 46px; }
  .expense-amount { grid-column: 2; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
  .bar-row { grid-template-columns: 1fr; gap: 4px; }
  .project-head h2 { font-size: 1.15rem; }
  .ph-actions { width: 100%; }
  .login-page { padding: 16px; }
  .login-hero { padding: 24px 20px; border-radius: 22px; text-align: center; }
  .hero-logo { width: 84px; height: 84px; }
  .hero-divider { margin: 12px auto; }
  .hero-aff { display: none; }
  .login-card { padding: 24px 18px 20px; border-radius: 22px; }
  .signatures { grid-template-columns: 1fr; }
  /* ตารางโครงการบนมือถือ → ซ่อนคอลัมน์รอง */
  .projects-table th:nth-child(3), .projects-table td:nth-child(3),
  .projects-table th:nth-child(5), .projects-table td:nth-child(5) { display: none; }
}

/* ==========================================================
   Print
   ========================================================== */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .expense-list.collapsed .expense { display: grid !important; }
  .show-all,
  .sidebar, .topbar, .foot, .no-print, .alert, .row-actions, .toolbar, .chips, .tabs, form .btn, .sticky-actions, .ph-actions, .menu-btn { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .card, .stat-card, .kpi, .hk { box-shadow: none !important; break-inside: avoid; }
  .card { border: 1px solid #ccd; }
  .hk { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .progress, .badge, .bar-track, .donut, .columns { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .grid-2, .grid-3 { display: block; }
  .update-grid #forms { display: none; }
  a { color: inherit; }
  body[data-view] .view-table { display: block !important; }
  body[data-view] .view-cards { display: none !important; }
}
