:root {
  --bg: #F5F5FB;
  --surface: #FFFFFF;
  --surface-2: #FAFAFE;
  --text: #1A1830;
  --text-soft: #5B5870;
  --text-faint: #9794AC;
  --line: #ECEAF6;
  --line-soft: #F3F1FA;

  --violet: #7C5CFC;
  --violet-deep: #5B3DE0;
  --violet-soft: #EEE9FF;
  --violet-softer: #F5F2FF;
  --coral: #FF7A59;
  --coral-soft: #FFEDE7;
  --emerald: #18B58A;
  --emerald-soft: #DEF7EF;
  --amber: #F5A623;
  --amber-soft: #FDF0D9;
  --rose: #F2487E;
  --rose-soft: #FDE4ED;
  --sky: #3B9EF5;
  --sky-soft: #E1F0FD;

  --grad: linear-gradient(135deg, #7C5CFC 0%, #9D7CFF 50%, #C16BF0 100%);
  --grad-coral: linear-gradient(135deg, #FF7A59 0%, #FF9E7D 100%);

  --shadow-sm: 0 1px 2px rgba(26,24,48,0.04), 0 2px 6px rgba(26,24,48,0.04);
  --shadow: 0 2px 8px rgba(26,24,48,0.05), 0 8px 24px rgba(26,24,48,0.06);
  --shadow-lg: 0 8px 32px rgba(124,92,252,0.10), 0 2px 8px rgba(26,24,48,0.04);
  --shadow-violet: 0 8px 24px rgba(124,92,252,0.28);

  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --r-pill: 999px;

  --font-head: "Plus Jakarta Sans", -apple-system, sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font-body); color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
h1,h2,h3,h4 { font-family: var(--font-head); margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
a { color: var(--violet-deep); text-decoration: none; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
::selection { background: var(--violet-soft); }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }
i.ti { line-height: 1; }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #DEDBEC; border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #CFCBE3; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: none; border-radius: var(--r-pill); padding: 10px 18px; font-size: 13px; font-weight: 600; cursor: pointer; transition: transform .12s ease, box-shadow .15s ease, background .15s ease; white-space: nowrap; }
.btn:active { transform: scale(0.97); }
.btn i { font-size: 16px; }
.btn-primary { background: var(--violet); color: #fff; box-shadow: var(--shadow-violet); }
.btn-primary:hover { background: var(--violet-deep); transform: translateY(-1px); }
.btn-secondary { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--line-soft); color: var(--text); }
.btn-danger { background: var(--rose-soft); color: var(--rose); }
.btn-danger:hover { background: #fbd3e1; }
.btn-sm { padding: 7px 13px; font-size: 12px; }
.btn-block { width: 100%; }

/* inputs */
input, select, textarea { width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--surface); font-size: 13.5px; color: var(--text); font-family: inherit; transition: border-color .15s ease, box-shadow .15s ease; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 4px var(--violet-softer); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { resize: vertical; min-height: 44px; }
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='%235B5870' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; cursor: pointer; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 7px; }

/* ===== LOGIN ===== */
#login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; background: #14112B; }
#login-view::before { content:""; position: absolute; width: 600px; height: 600px; border-radius: 50%; background: radial-gradient(circle, rgba(124,92,252,0.55), transparent 70%); top: -180px; left: -120px; }
#login-view::after { content:""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: radial-gradient(circle, rgba(255,122,89,0.40), transparent 70%); bottom: -180px; right: -120px; }
.login-card { position: relative; z-index: 1; width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--r-lg); padding: 38px 36px 30px; box-shadow: 0 24px 70px rgba(0,0,0,0.4); }
.login-logo { width: 52px; height: 52px; border-radius: 15px; background: var(--grad); display: grid; place-items: center; box-shadow: var(--shadow-violet); margin-bottom: 18px; }
.login-logo i { color: #fff; font-size: 27px; }
.login-card h2 { font-size: 23px; font-weight: 800; }
.login-sub { font-size: 13.5px; color: var(--text-soft); margin: 5px 0 26px; }
.login-field { margin-bottom: 15px; }
.login-hint { font-size: 12px; color: var(--text-faint); margin-top: 16px; text-align: center; line-height: 1.5; }
.login-error { background: var(--rose-soft); color: var(--rose); border-radius: var(--r-sm); padding: 11px 14px; font-size: 12.5px; margin-bottom: 16px; font-weight: 500; }

/* ===== APP SHELL ===== */
#app-view { display: flex; min-height: 100vh; }
.sidebar { width: 252px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 22px 16px 16px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.brand-logo { width: 38px; height: 38px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; box-shadow: var(--shadow-violet); flex-shrink: 0; }
.brand-logo i { color: #fff; font-size: 20px; }
.brand-name { font-family: var(--font-head); font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.brand-name span { color: var(--violet); }

.nav-label { padding: 16px 12px 7px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin-bottom: 2px; font-size: 13.5px; font-weight: 500; color: var(--text-soft); cursor: pointer; border-radius: var(--r-sm); transition: background .13s ease, color .13s ease; }
.nav-item i { font-size: 19px; color: var(--text-faint); transition: color .13s ease; }
.nav-item:hover { background: var(--line-soft); color: var(--text); }
.nav-item:hover i { color: var(--text-soft); }
.nav-item.active { background: var(--violet-soft); color: var(--violet-deep); font-weight: 600; }
.nav-item.active i { color: var(--violet); }

.project-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm); }
.avatar { width: 36px; height: 36px; border-radius: 11px; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; font-family: var(--font-head); }
.user-meta { flex: 1; min-width: 0; }
.user-meta .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta .role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }
.role-switch { margin-top: 10px; width: 100%; background: var(--violet-softer); color: var(--violet-deep); font-size: 12px; }
.role-switch:hover { background: var(--violet-soft); }
.role-switch i { font-size: 15px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { padding: 22px 30px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.topbar .eyebrow { font-size: 12px; font-weight: 600; color: var(--violet); margin-bottom: 3px; }
.topbar h1 { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; }
.content { padding: 22px 30px 48px; flex: 1; }

/* ===== TABS ===== */
.tabbar { display: inline-flex; gap: 3px; background: var(--surface); padding: 5px; border-radius: var(--r-pill); box-shadow: var(--shadow-sm); margin-bottom: 24px; }
.tabbtn { padding: 9px 18px; font-size: 13px; font-weight: 600; color: var(--text-soft); background: transparent; border: none; border-radius: var(--r-pill); cursor: pointer; transition: all .15s ease; }
.tabbtn:hover { color: var(--text); }
.tabbtn.active { background: var(--violet); color: #fff; box-shadow: var(--shadow-violet); }

/* ===== CARDS ===== */
.card { background: var(--surface); border-radius: var(--r); padding: 22px 24px; margin-bottom: 22px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-head h3 { font-size: 16px; }
.card-head .sub, .sub { font-size: 13px; color: var(--text-soft); margin-top: 3px; }
.card-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.card-title-row .ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.card-title-row .ico i { font-size: 19px; }
.card-title-row h3 { font-size: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ===== STAT TILES ===== */
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat .ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; }
.stat .ico i { font-size: 20px; }
.stat .label { font-size: 12.5px; color: var(--text-soft); font-weight: 500; margin-bottom: 4px; }
.stat .value { font-family: var(--font-head); font-size: 27px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.stat .delta { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.ico-violet { background: var(--violet-soft); color: var(--violet); }
.ico-coral { background: var(--coral-soft); color: var(--coral); }
.ico-emerald { background: var(--emerald-soft); color: var(--emerald); }
.ico-amber { background: var(--amber-soft); color: var(--amber); }
.ico-rose { background: var(--rose-soft); color: var(--rose); }
.ico-sky { background: var(--sky-soft); color: var(--sky); }
.bar-accent::after { content:""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.acc-violet::after { background: var(--violet); }
.acc-emerald::after { background: var(--emerald); }
.acc-coral::after { background: var(--coral); }
.acc-rose::after { background: var(--rose); }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: end; }
.form-grid .field { margin: 0; }
.form-grid .field.span-2 { grid-column: span 2; }

/* ===== TABLES ===== */
.table-card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.table-card.table-wrap { overflow-x: auto; margin-bottom: 22px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 13px 18px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); background: var(--surface-2); white-space: nowrap; }
tbody td { padding: 13px 18px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--violet-softer); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ledger tfoot td { background: var(--violet-softer); font-weight: 700; border-top: 2px solid var(--violet-soft); font-variant-numeric: tabular-nums; }
.empty-row td { text-align: center; color: var(--text-faint); padding: 36px 18px; font-style: normal; }
.link-cell a { font-size: 12.5px; word-break: break-all; display: inline-flex; align-items: center; gap: 4px; }
.link-cell .none { color: var(--text-faint); }
.cell-strong { font-weight: 600; }

/* ===== PILL BADGES ===== */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 4px 11px; border-radius: var(--r-pill); white-space: nowrap; }
.pill i { font-size: 13px; }
.pill-up { background: var(--emerald-soft); color: var(--emerald); }
.pill-down { background: var(--rose-soft); color: var(--rose); }
.pill-flat { background: var(--line); color: var(--text-soft); }
.pill-violet { background: var(--violet-soft); color: var(--violet-deep); }
.pill-amber { background: var(--amber-soft); color: #B5790A; }
.pill-coral { background: var(--coral-soft); color: #D9512C; }

/* ===== MISC ===== */
.section-title { font-size: 13px; font-weight: 700; color: var(--text); margin: 30px 0 14px; display: flex; align-items: center; gap: 8px; }
.section-title:first-child { margin-top: 0; }
.section-title i { color: var(--violet); font-size: 17px; }
.help-text { font-size: 12.5px; color: var(--text-faint); }
.month-picker { display: flex; align-items: center; gap: 9px; }
.month-picker select { width: auto; min-width: 150px; }
.month-picker .help-text { white-space: nowrap; }
.two-col { display: grid; grid-template-columns: 1.25fr 1fr; gap: 22px; }
.chart-box { position: relative; height: 270px; }
.empty-state { text-align: center; padding: 56px 24px; color: var(--text-faint); }
.empty-state i { font-size: 38px; color: var(--line); }
.empty-state p { margin-top: 12px; font-size: 13.5px; }

.banner-cta { background: var(--grad); border-radius: var(--r); padding: 22px 26px; display: flex; align-items: center; justify-content: space-between; gap: 18px; box-shadow: var(--shadow-violet); margin-bottom: 22px; }
.banner-cta h3 { color: #fff; font-size: 17px; }
.banner-cta .sub { color: rgba(255,255,255,0.85); margin-top: 3px; }
.banner-cta .btn { background: rgba(255,255,255,0.18); color: #fff; backdrop-filter: blur(4px); }
.banner-cta .btn:hover { background: rgba(255,255,255,0.28); }

/* toasts */
#toast-host { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 999; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--surface); color: var(--text); padding: 13px 18px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; transform: translateX(20px); transition: opacity .25s ease, transform .25s ease; }
.toast i { font-size: 18px; }
.toast--in { opacity: 1; transform: translateX(0); }
.toast--success i { color: var(--emerald); }
.toast--error i { color: var(--rose); }
.toast--default i { color: var(--violet); }

@media (max-width: 980px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .brand { padding: 0 12px 0 4px; border: none; }
  .nav-label { display: none; }
  #nav-primary, #project-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: none; display: flex; align-items: center; gap: 10px; }
  .role-switch { margin: 0; width: auto; }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .field.span-2 { grid-column: span 1; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ===== Autocomplete dropdown (platform field) ===== */
.autocomplete { position: relative; }
.autocomplete-menu { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border-radius: var(--r-sm); box-shadow: var(--shadow-lg); max-height: 220px; overflow-y: auto; padding: 5px; }
.autocomplete-item { padding: 8px 11px; border-radius: 8px; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.autocomplete-item i { font-size: 15px; color: var(--text-faint); }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--violet-soft); color: var(--violet-deep); }
.autocomplete-item:hover i, .autocomplete-item.active i { color: var(--violet); }
.autocomplete-empty { padding: 8px 11px; font-size: 12.5px; color: var(--text-faint); }

/* ===== Entry mode toggle (single / bulk) ===== */
.mode-toggle { display: inline-flex; gap: 3px; background: var(--surface-2); padding: 4px; border-radius: var(--r-pill); margin-bottom: 18px; }
.mode-btn { padding: 7px 15px; font-size: 12.5px; font-weight: 600; color: var(--text-soft); background: transparent; border: none; border-radius: var(--r-pill); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.mode-btn i { font-size: 15px; }
.mode-btn.active { background: var(--violet); color: #fff; box-shadow: var(--shadow-violet); }

/* ===== Bulk paste ===== */
.bulk-area { width: 100%; min-height: 150px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; }
.bulk-hint { font-size: 12.5px; color: var(--text-soft); margin: 8px 0 14px; background: var(--violet-softer); border-radius: var(--r-sm); padding: 11px 14px; }
.bulk-hint code { background: var(--surface); padding: 1px 6px; border-radius: 5px; font-size: 11.5px; color: var(--violet-deep); }
.bulk-preview { margin-top: 14px; }
.bulk-preview-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; padding: 7px 0; border-top: 1px solid var(--line-soft); }
.bulk-preview-row .idx { width: 22px; height: 22px; border-radius: 6px; background: var(--violet-soft); color: var(--violet-deep); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.bulk-preview-row .pf { font-weight: 600; min-width: 110px; }
.bulk-preview-row .lk { color: var(--text-soft); word-break: break-all; flex: 1; }
.bulk-preview-row.bad .lk { color: var(--rose); }

/* ===== Inline edit ===== */
.editing-row td { background: var(--violet-softer) !important; }
.inline-input { padding: 6px 9px; font-size: 12.5px; border-radius: 7px; }
.row-actions { display: inline-flex; gap: 6px; }
.icon-btn { width: 30px; height: 30px; border-radius: 8px; border: none; display: grid; place-items: center; cursor: pointer; background: var(--surface-2); color: var(--text-soft); transition: background .12s ease, color .12s ease; }
.icon-btn i { font-size: 15px; }
.icon-btn:hover { background: var(--violet-soft); color: var(--violet); }
.icon-btn.danger:hover { background: var(--rose-soft); color: var(--rose); }
.icon-btn.save:hover { background: var(--emerald-soft); color: var(--emerald); }

/* ===== Activity feed (admin) ===== */
.feed-item { display: flex; align-items: flex-start; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line-soft); }
.feed-item:first-child { border-top: none; }
.feed-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.feed-ico i { font-size: 18px; }
.feed-body { flex: 1; min-width: 0; }
.feed-line { font-size: 13.5px; }
.feed-line strong { font-weight: 600; }
.feed-meta { font-size: 12px; color: var(--text-faint); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.feed-meta .lag { color: var(--amber); font-weight: 600; }
.feed-link { font-size: 12px; word-break: break-all; }

/* ===== Gap calendar ===== */
.gap-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 6px; }
.gap-cell { aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.gap-cell.has { background: var(--emerald-soft); color: var(--emerald); }
.gap-cell.miss { background: var(--rose-soft); color: var(--rose); }
.gap-cell.future { background: var(--surface-2); color: var(--text-faint); opacity: 0.5; }
.gap-cell.dow { background: transparent; color: var(--text-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.gap-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--text-soft); }
.gap-legend span { display: inline-flex; align-items: center; gap: 6px; }
.gap-legend .sw { width: 13px; height: 13px; border-radius: 4px; }

/* ===== DA badge ===== */
.da-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 2px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.da-hi { background: var(--emerald-soft); color: var(--emerald); }
.da-mid { background: var(--amber-soft); color: #B5790A; }
.da-lo { background: var(--line); color: var(--text-soft); }
