:root {
  --primary: #d81f2a;
  --primary-dark: #b4161f;
  --accent: #111827;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --sidebar: #141821;
  --sidebar-text: #d7dbe3;
  --text: #172033;
  --muted: #64748b;
  --line: #e4e8ee;
  --line-strong: #cfd6df;
  --success: #0f9f6e;
  --warning: #c47c08;
  --danger: #dc2626;
  --info: #2563eb;
  --radius: 10px;
  --font: Inter, "Segoe UI", Arial, sans-serif;
  --font-size: 14px;
  --shadow: 0 8px 28px rgba(15, 23, 42, .07);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: .98rem; font-weight: 700; }
p { margin: 0 0 .8rem; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 50;
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; transition: transform .22s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px; padding: 17px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; }
.sidebar-brand .brand-name { font-weight: 750; color: #fff; font-size: .98rem; line-height: 1.15; }
.sidebar-brand .brand-sub { font-size: .68rem; color: #98a1b3; letter-spacing: .07em; text-transform: uppercase; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #343c4c; border-radius: 4px; }
.nav-section { margin: 15px 0 5px; padding: 0 10px; font-size: .64rem; letter-spacing: .11em; text-transform: uppercase; color: #6e788b; font-weight: 700; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; font-size: .875rem; margin: 1px 0;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; box-shadow: 0 5px 16px rgba(216,31,42,.25); }
.nav-link .icon { width: 17px; height: 17px; opacity: .9; }
.nav-badge { margin-left: auto; background: rgba(255,255,255,.12); border-radius: 999px; padding: 1px 7px; font-size: .68rem; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: .72rem; color: #8b94a6; }

.main { margin-left: 248px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 62px; background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
}
.topbar .page-title { font-size: 1rem; font-weight: 700; margin: 0; }
.topbar .page-sub { font-size: .74rem; color: var(--muted); }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px; cursor: pointer; color: var(--text); }
.topbar-spacer { flex: 1; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 8px 5px 5px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.user-meta { line-height: 1.2; }
.user-meta strong { display: block; font-size: .8rem; }
.user-meta span { display: block; font-size: .68rem; color: var(--muted); }
.content { padding: 24px; flex: 1; width: 100%; max-width: 1500px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .eyebrow { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--primary); font-weight: 700; margin-bottom: 3px; }
.page-head p { color: var(--muted); margin: 4px 0 0; font-size: .85rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 20px; }
.panel { overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }
.section-gap { margin-top: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card:before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); opacity: .85; }
.stat-card.green:before { background: var(--success); }
.stat-card.blue:before { background: var(--info); }
.stat-card.orange:before { background: var(--warning); }
.stat-label { color: var(--muted); font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.45rem; font-weight: 750; margin-top: 5px; letter-spacing: -.02em; }
.stat-note { color: var(--muted); font-size: .72rem; margin-top: 3px; }
.stat-icon { position: absolute; right: 13px; top: 13px; color: var(--primary); opacity: .14; }
.stat-icon .icon { width: 34px; height: 34px; }

.grid-2 { display: grid; grid-template-columns: 1.35fr .65fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-2-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar form { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px; }
.search-box { position: relative; flex: 1; max-width: 380px; }
.search-box .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search-box input { padding-left: 34px; }
.toolbar .muted { font-size: .8rem; }

input, select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: inherit; font-size: .875rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(216,31,42,.13); border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--primary); }
label { display: block; font-weight: 600; font-size: .78rem; margin-bottom: 5px; color: #374151; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.field .error { font-size: .75rem; color: var(--danger); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.form-actions { display: flex; gap: 9px; align-items: center; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.check-field { display: flex; align-items: center; gap: 8px; padding-top: 24px; }
.check-field label { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 14px;
  font: inherit; font-size: .84rem; font-weight: 650; cursor: pointer; white-space: nowrap;
  background: #fff; color: var(--text); transition: .15s;
}
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-dark { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-dark:hover { background: #000; color: #fff; }
.btn-outline { border-color: var(--line-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: .76rem; border-radius: 7px; }
.btn-icon { padding: 7px; }
.btn-block { width: 100%; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.data-table th {
  text-align: left; padding: 10px 13px; background: #f8fafc; color: #5a6576;
  font-size: .68rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 11px 13px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.data-table tbody tr:hover { background: #fbfcfe; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num, .data-table .money { text-align: right; white-space: nowrap; }
.data-table .actions { text-align: right; white-space: nowrap; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .btn { padding: 5px 7px; }
.row-actions .icon { width: 15px; height: 15px; }
.empty { text-align: center; padding: 38px 20px; color: var(--muted); }
.empty .icon { width: 38px; height: 38px; opacity: .35; margin-bottom: 8px; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.badge-success { background: #e8f8f1; color: #0a7a54; }
.badge-info { background: #eaf1fe; color: #1d4ed8; }
.badge-warning { background: #fff6e5; color: #a15f00; }
.badge-danger { background: #fdecec; color: #b91c1c; }
.badge-muted { background: #f1f4f8; color: #5b6678; }

.pagination { display: flex; gap: 4px; padding: 14px 16px; flex-wrap: wrap; }
.page-link { display: inline-flex; min-width: 32px; height: 32px; align-items: center; justify-content: center; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; font-size: .78rem; color: var(--text); background: #fff; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link.disabled { color: #aeb6c2; pointer-events: none; background: #f8fafc; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .84rem; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 18px; overflow-x: auto; }
.tab { padding: 11px 13px; font-size: .82rem; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; font-size: .84rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { padding: 10px 0; border-bottom: 1px dashed #e8ecf1; font-size: .84rem; }
.list-clean li:last-child { border-bottom: 0; }

.timeline { position: relative; padding-left: 20px; }
.timeline:before { content: ""; position: absolute; left: 6px; top: 5px; bottom: 5px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding: 0 0 16px 8px; font-size: .82rem; }
.timeline-item:before { content: ""; position: absolute; left: -18px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.timeline-item .time { color: var(--muted); font-size: .72rem; }

.comment { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.comment.internal { background: #fffbeb; border-color: #fde68a; }
.comment .comment-head { display: flex; justify-content: space-between; gap: 8px; font-size: .78rem; margin-bottom: 6px; }
.comment .comment-head strong { font-size: .82rem; }
.comment .comment-body { font-size: .84rem; white-space: pre-wrap; }

.invoice-lines { width: 100%; border-collapse: collapse; }
.invoice-lines th { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; padding: 6px 6px; }
.invoice-lines td { padding: 4px 4px; vertical-align: top; }
.invoice-lines input, .invoice-lines select { padding: 7px 8px; font-size: .8rem; }
.invoice-lines .line-total { padding-top: 11px; text-align: right; font-weight: 650; white-space: nowrap; }
.invoice-totals { margin-left: auto; width: 320px; max-width: 100%; }
.invoice-totals .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: .85rem; }
.invoice-totals .row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 750; font-size: .95rem; }

.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; background: #fff; }
.auth-side { background: radial-gradient(circle at 20% 20%, rgba(216,31,42,.35), transparent 40%), linear-gradient(145deg, #141821, #241013 65%, #5c1016); color: #fff; padding: 52px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side:after { content: ""; position: absolute; width: 420px; height: 420px; border: 1px solid rgba(255,255,255,.09); border-radius: 50%; right: -160px; bottom: -160px; box-shadow: 0 0 0 70px rgba(255,255,255,.025), 0 0 0 140px rgba(255,255,255,.02); }
.auth-brand { display: flex; align-items: center; gap: 13px; position: relative; z-index: 1; }
.auth-brand img { width: 54px; height: 54px; background: #fff; border-radius: 10px; padding: 4px; object-fit: contain; }
.auth-brand strong { font-size: 1.1rem; display: block; }
.auth-brand span { color: #b9c0cd; font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; }
.auth-side h2 { font-size: 2.1rem; line-height: 1.15; letter-spacing: -.03em; margin: 28px 0 12px; max-width: 520px; position: relative; z-index: 1; }
.auth-side p { color: #c6ccd7; max-width: 460px; position: relative; z-index: 1; }
.auth-points { display: grid; gap: 10px; position: relative; z-index: 1; }
.auth-point { display: flex; gap: 9px; align-items: center; color: #dfe3ea; font-size: .84rem; }
.auth-point .icon { color: #ff7b82; width: 17px; height: 17px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-box { width: 100%; max-width: 390px; }
.auth-box h1 { font-size: 1.7rem; }
.auth-box .sub { color: var(--muted); margin-bottom: 26px; }
.auth-box .field { margin-bottom: 16px; }
.auth-foot { margin-top: 18px; font-size: .76rem; color: var(--muted); text-align: center; }

.portal-shell { min-height: 100vh; background: var(--bg); }
.portal-top { background: var(--sidebar); color: #fff; }
.portal-top-inner { max-width: 1180px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 14px; }
.portal-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.portal-brand img { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.portal-nav { display: flex; gap: 4px; margin-left: 18px; flex-wrap: wrap; }
.portal-nav a { color: #cbd2de; padding: 7px 10px; border-radius: 7px; font-size: .82rem; }
.portal-nav a:hover, .portal-nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.portal-user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: .8rem; }
.portal-user .avatar { background: var(--primary); }
.portal-content { max-width: 1180px; margin: 0 auto; padding: 24px 20px 50px; }
.portal-hero { background: linear-gradient(120deg, var(--accent), #321015); color: #fff; border-radius: 14px; padding: 26px; margin-bottom: 20px; position: relative; overflow: hidden; }
.portal-hero h1 { color: #fff; margin-bottom: 5px; }
.portal-hero p { color: #cbd2de; margin: 0; }
.portal-hero .badge { position: absolute; right: 22px; top: 22px; background: rgba(255,255,255,.14); color: #fff; }

.print-only { display: none; }
@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .pagination, .btn, .flash { display: none !important; }
  .main { margin: 0; } .content { padding: 0; max-width: none; }
  .panel, .card { box-shadow: none; border: 0; }
  body { background: #fff; }
  .print-only { display: block; }
}
@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: 20px 0 50px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-2, .grid-2-even { grid-template-columns: 1fr; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-form { min-height: 100vh; }
}
@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; height: 56px; }
  .user-meta { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 1.2rem; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .page-head { flex-direction: column; }
  .toolbar form { max-width: none; }
  .invoice-lines { min-width: 680px; }
  .portal-nav { display: none; }
  .portal-user { margin-left: auto; }
  .data-table th, .data-table td { padding: 9px 10px; }
}
.overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 40; }
.overlay.show { display: block; }

.notif-wrap { position: relative; }
.notif-btn { position: relative; }
.notif-badge { position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .62rem; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; }
.notif-menu { display: none; position: absolute; right: 0; top: 42px; width: 370px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 50px rgba(15,23,42,.2); z-index: 120; overflow: hidden; }
.notif-menu.show { display: block; }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: .84rem; }
.notif-head form button { border: 0; background: none; color: var(--primary); font: inherit; font-size: .72rem; font-weight: 650; cursor: pointer; padding: 0; }
.notif-list { max-height: 370px; overflow-y: auto; }
.notif-item { display: block; width: 100%; border: 0; border-bottom: 1px solid #eef1f5; background: #fff; text-align: left; padding: 11px 14px; cursor: pointer; font: inherit; }
.notif-item:hover { background: #fbfcfe; }
.notif-title { font-weight: 700; font-size: .8rem; color: var(--text); }
.notif-msg { font-size: .74rem; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.notif-time { font-size: .66rem; color: #94a3b8; margin-top: 3px; }
.notif-empty { padding: 24px 14px; text-align: center; color: var(--muted); font-size: .8rem; }
.notif-all { display: block; padding: 10px 14px; text-align: center; font-size: .76rem; font-weight: 650; border-top: 1px solid var(--line); }
@media (max-width: 720px) { .notif-menu { position: fixed; left: 10px; right: 10px; top: 60px; width: auto; } }

.roster-daily select { min-width: 210px; padding: 6px 8px; font-size: .78rem; }
.roster-daily td { padding: 7px 10px; }
.roster-weekend { background: #fff7ed !important; }
.roster-holiday { background: #eef6ff !important; }
.roster-daily .badge { margin-left: 4px; }

.report-chain { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.report-chain-item { display: block; width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: #f8fafc; color: var(--text); }
.report-chain-item strong { display: block; font-size: .84rem; }
.report-chain-item span { display: block; font-size: .72rem; color: var(--muted); }
.report-chain-arrow { color: var(--muted); font-size: .9rem; padding-left: 12px; }
.org-tree-wrap { overflow-x: auto; padding: 20px 10px 30px; }
.org-tree, .org-tree ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; }
.org-tree li { position: relative; padding: 24px 8px 0; text-align: center; }
.org-tree li::before, .org-tree li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 1px solid var(--line-strong); width: 50%; height: 24px; }
.org-tree li::after { right: auto; left: 50%; border-left: 1px solid var(--line-strong); }
.org-tree li:only-child::after, .org-tree li:only-child::before { display: none; }
.org-tree li:only-child { padding-top: 0; }
.org-tree li:first-child::before, .org-tree li:last-child::after { border: 0 none; }
.org-tree li:last-child::before { border-right: 1px solid var(--line-strong); border-radius: 0 6px 0 0; }
.org-tree li:first-child::after { border-radius: 6px 0 0 0; }
.org-tree ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 1px solid var(--line-strong); width: 0; height: 24px; }
.org-tree > li { padding-top: 0; }
.org-tree > li::before, .org-tree > li::after { display: none; }
.org-node { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; min-width: 150px; max-width: 190px; padding: 10px 12px; border: 1px solid var(--line); border-top: 3px solid var(--primary); border-radius: 9px; background: #fff; box-shadow: var(--shadow); color: var(--text); }
.org-node strong { font-size: .82rem; }
.org-role { font-size: .72rem; color: var(--text); }
.org-dept { font-size: .68rem; color: var(--muted); }
.org-node .badge { margin-top: 3px; }

/* Customer portal shell */
.portal-app { display: flex; min-height: 100vh; background: var(--bg); }
.portal-sidebar { width: 260px; flex: 0 0 260px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding: 22px 14px 16px; background: linear-gradient(180deg, var(--sidebar), #0d111a); color: #fff; z-index: 60; }
.portal-sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 14px; border-bottom: 1px solid rgba(255,255,255,.1); color: #fff; }
.portal-sidebar-brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 9px; background: #fff; padding: 3px; }
.portal-sidebar-brand span { display: flex; flex-direction: column; min-width: 0; }
.portal-sidebar-brand strong { font-size: .92rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-sidebar-brand small { font-size: .67rem; color: #9aa5b6; text-transform: uppercase; letter-spacing: .08em; }
.portal-side-nav { display: flex; flex-direction: column; gap: 16px; }
.portal-nav-group { display: flex; flex-direction: column; gap: 3px; }
.portal-nav-label { font-size: .62rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #7f8a9d; padding: 0 10px 5px; }
.portal-nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; color: #c6cfdd; font-size: .84rem; font-weight: 550; transition: background .15s, color .15s, transform .15s; }
.portal-nav-link .icon { width: 17px; height: 17px; opacity: .9; }
.portal-nav-link:hover { background: rgba(255,255,255,.08); color: #fff; transform: translateX(1px); }
.portal-nav-link.active { background: linear-gradient(90deg, var(--primary), #9d111c); color: #fff; box-shadow: 0 8px 20px rgba(216,31,42,.25); }
.portal-side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 12px; }
.portal-side-user { display: flex; align-items: center; gap: 9px; min-width: 0; }
.portal-side-user div:last-child { min-width: 0; display: flex; flex-direction: column; }
.portal-side-user strong { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-side-user small { font-size: .7rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.portal-side-actions { display: flex; align-items: center; gap: 8px; }
.portal-signout { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 10px; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; color: #e2e8f0; font-size: .76rem; font-weight: 600; }
.portal-signout:hover { background: rgba(255,255,255,.1); color: #fff; }
.portal-theme-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.06); color: #fff; cursor: pointer; font-size: 1rem; line-height: 1; }
.portal-theme-btn:hover { background: rgba(255,255,255,.14); }
.portal-theme-btn .theme-icon-dark { display: none; }
html.portal-dark .portal-theme-btn .theme-icon-light { display: none; }
html.portal-dark .portal-theme-btn .theme-icon-dark { display: inline; }
.portal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.portal-mobilebar { display: none; }
.portal-content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 30px 44px; flex: 1; }
.portal-footer { padding: 16px 24px 24px; text-align: center; font-size: .72rem; color: var(--muted); }
.portal-overlay { display: none; }

@media (max-width: 1024px) {
  .portal-sidebar { position: fixed; left: 0; top: 0; width: 280px; flex-basis: 280px; transform: translateX(-100%); transition: transform .25s ease; box-shadow: 20px 0 50px rgba(0,0,0,.35); }
  body.portal-menu-open .portal-sidebar { transform: translateX(0); }
  .portal-overlay { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  body.portal-menu-open .portal-overlay { opacity: 1; pointer-events: auto; }
  .portal-mobilebar { position: sticky; top: 0; z-index: 45; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--sidebar); color: #fff; box-shadow: 0 6px 22px rgba(15,23,42,.18); }
  .portal-menu-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid rgba(255,255,255,.16); border-radius: 9px; background: rgba(255,255,255,.06); color: #fff; cursor: pointer; }
  .portal-mobile-brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: .86rem; min-width: 0; }
  .portal-mobile-brand img { width: 28px; height: 28px; object-fit: contain; border-radius: 7px; background: #fff; padding: 2px; }
  .portal-mobile-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .portal-mobilebar .portal-theme-btn { margin-left: auto; }
}
@media (max-width: 720px) {
  .portal-content { padding: 16px 12px 34px; }
  .portal-footer { padding: 12px 14px 20px; }
  .portal-hero { padding: 20px 18px; border-radius: 12px; }
  .portal-hero .badge { position: static; display: inline-block; margin-bottom: 8px; }
  .page-head { gap: 10px; }
  .page-head .page-actions { width: 100%; flex-wrap: wrap; }
  .page-head .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .stat-grid { gap: 10px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 620px; }
}
.portal-modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.portal-modal.open { display: flex; }
.portal-modal-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 18, .62); backdrop-filter: blur(3px); }
.portal-modal-card { position: relative; width: min(640px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 28px 80px rgba(2,6,23,.35); animation: portalModalIn .18s ease-out; }
.portal-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.portal-modal-head h3 { margin: 0; font-size: 1rem; }
.portal-modal-close { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; font-size: 1.15rem; line-height: 1; }
.portal-modal-close:hover { background: var(--bg); }
.portal-modal-body { padding: 18px; }
.portal-modal-body .kv { margin: 0; }
.portal-detail-note { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); line-height: 1.7; }
.portal-detail-note strong { display: block; margin-bottom: 6px; }
@keyframes portalModalIn { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }