:root{
  --blue:#037EF3; --blue-deep:#0250B5; --blue-soft:#E8F2FF;
  --ink:#0B1220; --canvas:#F7F9FC; --card:#FFFFFF; --muted:#64748B;
  --line:#EDF1F7; --coral:#EF4444; --coral-soft:#FEECEC;
  --green:#10B981; --green-soft:#E7FAF3;
  --amber:#F59E0B; --amber-soft:#FEF6E7;
  --sidebar-w:236px;
  --radius:14px; --radius-lg:20px;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:Inter,-apple-system,BlinkMacSystemFont,sans-serif;
  background:var(--canvas); color:var(--ink);
  -webkit-tap-highlight-color:transparent;
  min-height:100vh;
}
h1,h2,h3,.brand,.stat-value,.section-title{font-family:'Space Grotesk',Inter,sans-serif;}
a{color:var(--blue); text-decoration:none;}
button{font-family:inherit;}
.hidden{display:none !important;}
::selection{background:var(--blue-soft);}

/* ============ LOGIN ============ */
#loginScreen{
  min-height:100vh; display:flex; align-items:stretch;
}
.login-hero{
  flex:1.1; background:linear-gradient(155deg,var(--blue) 0%,var(--blue-deep) 100%);
  color:#fff; display:flex; flex-direction:column; justify-content:center;
  padding:64px; position:relative; overflow:hidden;
}
.login-hero::before{
  content:""; position:absolute; width:520px; height:520px; border-radius:50%;
  background:rgba(255,255,255,.07); top:-160px; right:-140px;
}
.login-hero::after{
  content:""; position:absolute; width:340px; height:340px; border-radius:50%;
  background:rgba(255,255,255,.06); bottom:-120px; left:-80px;
}
.login-hero .hero-badge{
  display:inline-flex; align-items:center; gap:8px; background:rgba(255,255,255,.15);
  padding:6px 14px; border-radius:100px; font-size:12px; font-weight:600;
  width:fit-content; margin-bottom:28px; letter-spacing:.02em;
}
.login-hero h1{font-size:38px; line-height:1.2; margin:0 0 16px; max-width:460px; position:relative;}
.login-hero p{font-size:15px; opacity:.85; max-width:420px; line-height:1.6; position:relative;}
.login-hero .hero-stats{display:flex; gap:32px; margin-top:44px; position:relative;}
.login-hero .hero-stats div b{display:block; font-size:22px; font-family:'Space Grotesk',sans-serif;}
.login-hero .hero-stats div span{font-size:12px; opacity:.75;}
.login-panel{
  flex:0 0 460px; display:flex; align-items:center; justify-content:center; background:var(--card);
  padding:40px;
}
.login-form{width:100%; max-width:340px;}
.login-form h2{font-size:22px; margin:0 0 6px;}
.login-form p.sub{color:var(--muted); font-size:13.5px; margin:0 0 28px;}
.field{margin-bottom:16px;}
.field label{display:block; font-size:12px; font-weight:600; color:var(--muted); margin-bottom:6px; letter-spacing:.01em;}
.field input,.field select,.field textarea{
  width:100%; padding:11px 13px; border:1.5px solid var(--line); border-radius:10px;
  font-size:14px; font-family:inherit; background:var(--canvas); color:var(--ink);
  transition:border-color .15s, background .15s;
}
.field input:focus,.field select:focus,.field textarea:focus{
  outline:none; border-color:var(--blue); background:#fff;
}
button.btn{
  border:none; border-radius:10px; font-weight:700; font-size:14px; cursor:pointer;
  padding:11px 18px; display:inline-flex; align-items:center; justify-content:center; gap:7px;
  font-family:inherit; transition:transform .1s, box-shadow .15s, background .15s, opacity .15s;
}
button.btn:active{transform:scale(.98);}
button.btn:disabled{opacity:.55; cursor:not-allowed;}
button.btn-primary{background:var(--blue); color:#fff; box-shadow:0 6px 18px rgba(3,126,243,.25);}
button.btn-primary:hover:not(:disabled){background:var(--blue-deep);}
button.btn-block{width:100%;}
button.btn-ghost{background:#fff; color:var(--ink); border:1.5px solid var(--line);}
button.btn-ghost:hover:not(:disabled){border-color:var(--blue); color:var(--blue-deep);}
button.btn-danger{background:var(--coral-soft); color:#B91C1C;}
button.btn-danger:hover:not(:disabled){background:#fdd9d9;}
button.btn-sm{padding:7px 12px; font-size:12.5px; border-radius:8px;}
button.btn-icon{padding:8px; border-radius:9px;}
.error-msg{background:var(--coral-soft); border:1px solid #f6c6c6; color:#B91C1C; font-size:13px; padding:10px 13px; border-radius:10px; margin-bottom:14px;}
.ok-msg{background:var(--green-soft); border:1px solid #b9ecd6; color:#0B7A4B; font-size:13px; padding:10px 13px; border-radius:10px;}

/* ============ APP SHELL ============ */
#appShell{display:flex; min-height:100vh;}
#sidebar{
  width:var(--sidebar-w); flex-shrink:0; background:var(--card); border-right:1px solid var(--line);
  display:flex; flex-direction:column; position:fixed; top:0; bottom:0; left:0; z-index:20;
}
.sidebar-brand{padding:22px 22px 18px; display:flex; align-items:center; gap:10px; border-bottom:1px solid var(--line);}
.sidebar-brand .logo{
  width:34px; height:34px; border-radius:10px; background:linear-gradient(155deg,var(--blue),var(--blue-deep));
  display:flex; align-items:center; justify-content:center; color:#fff; font-weight:800; font-size:15px; flex-shrink:0;
}
.sidebar-brand .name{font-size:15px; font-weight:700; line-height:1.25;}
.sidebar-brand .name span{display:block; font-size:11px; color:var(--muted); font-weight:500; font-family:Inter,sans-serif;}
nav.sidebar-nav{padding:14px 12px; display:flex; flex-direction:column; gap:2px; flex:1; overflow-y:auto;}
nav.sidebar-nav a{
  display:flex; align-items:center; gap:11px; padding:10px 12px; border-radius:10px;
  color:var(--muted); font-size:13.5px; font-weight:600; transition:background .15s, color .15s;
}
nav.sidebar-nav a svg{width:17px; height:17px; flex-shrink:0;}
nav.sidebar-nav a:hover{background:var(--canvas); color:var(--ink);}
nav.sidebar-nav a.active{background:var(--blue-soft); color:var(--blue-deep);}
.sidebar-foot{padding:14px; border-top:1px solid var(--line);}
.user-chip{display:flex; align-items:center; gap:10px; padding:8px; border-radius:10px;}
.user-chip .avatar{
  width:32px; height:32px; border-radius:50%; background:var(--blue-soft); color:var(--blue-deep);
  display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; flex-shrink:0;
}
.user-chip .who{flex:1; min-width:0;}
.user-chip .who b{display:block; font-size:13px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.user-chip .who span{font-size:11px; color:var(--muted); text-transform:capitalize;}
.user-chip button{background:none; border:none; color:var(--muted); cursor:pointer; padding:6px; border-radius:8px;}
.user-chip button:hover{background:var(--coral-soft); color:#B91C1C;}

#mainArea{flex:1; margin-left:var(--sidebar-w); min-width:0;}
.topbar{
  position:sticky; top:0; z-index:10; background:rgba(247,249,252,.85); backdrop-filter:blur(8px);
  border-bottom:1px solid var(--line); padding:18px 32px; display:flex; align-items:center; justify-content:space-between;
  gap:16px;
}
.topbar h1{font-size:20px; margin:0;}
.topbar .sub{font-size:12.5px; color:var(--muted); margin-top:2px;}
.topbar-actions{display:flex; gap:10px; align-items:center;}
#mobileNavToggle{display:none;}

main.content{padding:26px 32px 64px; max-width:1280px;}
section.view{margin-bottom:8px;}
.section-title{font-size:15px; font-weight:700; margin:0 0 12px; display:flex; align-items:center; justify-content:space-between;}
.card{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:20px;}
.grid{display:grid; gap:16px;}
.grid.cols-2{grid-template-columns:1fr 1fr;}
.grid.cols-3{grid-template-columns:repeat(3,1fr);}
.grid.cols-4{grid-template-columns:repeat(4,1fr);}
.block-gap{margin-bottom:26px;}

/* ============ STAT CARDS ============ */
.stat-card{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:18px 20px; position:relative; overflow:hidden;}
.stat-card .stat-label{font-size:11.5px; font-weight:700; color:var(--muted); text-transform:uppercase; letter-spacing:.04em;}
.stat-card .stat-value{font-size:25px; font-weight:700; margin-top:8px;}
.stat-card .stat-sub{font-size:12px; color:var(--muted); margin-top:4px;}
.stat-card.acc-blue .stat-value{color:var(--blue-deep);}
.stat-card.acc-green .stat-value{color:var(--green);}
.stat-card.acc-red .stat-value{color:var(--coral);}
.stat-icon{position:absolute; top:16px; right:16px; width:34px; height:34px; border-radius:10px; display:flex; align-items:center; justify-content:center;}
.stat-icon svg{width:17px; height:17px;}
.stat-icon.blue{background:var(--blue-soft); color:var(--blue-deep);}
.stat-icon.green{background:var(--green-soft); color:var(--green);}
.stat-icon.red{background:var(--coral-soft); color:var(--coral);}

/* ============ TABLES ============ */
table{width:100%; border-collapse:collapse; font-size:13.5px;}
th{text-align:left; font-size:10.8px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); font-weight:700; padding:9px 12px; border-bottom:1px solid var(--line); white-space:nowrap;}
td{padding:11px 12px; border-bottom:1px solid var(--line); vertical-align:middle;}
tr:last-child td{border-bottom:none;}
tbody tr:hover{background:var(--canvas);}
td.num,th.num{text-align:right; font-variant-numeric:tabular-nums;}
.amount-pos{color:var(--green); font-weight:600;}
.amount-neg{color:var(--coral); font-weight:600;}
.muted-cell{color:var(--muted); font-size:12.5px;}
.table-scroll{overflow-x:auto;}
.empty-row{padding:36px 12px; text-align:center; color:var(--muted); font-size:13px;}

/* ============ CHIPS / TAGS ============ */
.chip-row{display:flex; flex-wrap:wrap; gap:7px; margin-top:8px;}
.chip{
  padding:6px 12px; border-radius:100px; background:var(--canvas); border:1px solid var(--line);
  font-size:12.5px; font-weight:600; color:var(--ink); cursor:pointer; transition:all .12s;
}
.chip:hover{border-color:var(--blue); color:var(--blue-deep); background:var(--blue-soft);}
.badge{font-size:10.5px; font-weight:700; padding:3px 9px; border-radius:100px; text-transform:uppercase; letter-spacing:.03em;}
.badge.role-admin{background:var(--blue-soft); color:var(--blue-deep);}
.badge.role-viewer{background:var(--canvas); color:var(--muted); border:1px solid var(--line);}
.badge.type-revenue{background:var(--green-soft); color:#0B7A4B;}
.badge.type-cost{background:var(--coral-soft); color:#B91C1C;}

/* ============ PROGRESS ============ */
.progress-track{height:6px; border-radius:100px; background:var(--line); overflow:hidden; margin-top:6px;}
.progress-fill{height:100%; background:var(--blue); border-radius:100px;}
.progress-fill.over{background:var(--coral);}
.progress-note{font-size:11px; color:var(--muted); margin-top:4px;}

/* ============ FORM ROW ============ */
.form-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:14px; align-items:end;}
.form-actions{display:flex; justify-content:flex-end; gap:10px; margin-top:16px; padding-top:16px; border-top:1px dashed var(--line);}

/* ============ MODAL ============ */
.modal-backdrop{
  position:fixed; inset:0; background:rgba(11,18,32,.45); backdrop-filter:blur(2px);
  display:flex; align-items:center; justify-content:center; z-index:100; padding:24px;
}
.modal{background:#fff; border-radius:18px; width:100%; max-width:560px; max-height:88vh; overflow-y:auto; box-shadow:0 30px 70px rgba(11,18,32,.25);}
.modal-head{padding:20px 24px; border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between;}
.modal-head h3{margin:0; font-size:17px;}
.modal-head button{background:none; border:none; cursor:pointer; color:var(--muted); padding:6px; border-radius:8px;}
.modal-head button:hover{background:var(--canvas); color:var(--ink);}
.modal-body{padding:22px 24px;}
.modal-foot{padding:16px 24px; border-top:1px solid var(--line); display:flex; justify-content:flex-end; gap:10px;}
.radio-toggle{display:flex; gap:8px;}
.radio-toggle label{flex:1; border:1.5px solid var(--line); border-radius:10px; padding:10px; text-align:center; font-size:13px; font-weight:700; cursor:pointer; color:var(--muted);}
.radio-toggle input{display:none;}
.radio-toggle input:checked + span{color:inherit;}
.radio-toggle label.rev-opt{color:#0B7A4B;}
.radio-toggle label.cost-opt{color:#B91C1C;}
.radio-toggle input:checked ~ .lbl-wrap, .radio-toggle label:has(input:checked){border-color:currentColor; background:currentColor; }
.radio-toggle label:has(input:checked).rev-opt{background:var(--green-soft);}
.radio-toggle label:has(input:checked).cost-opt{background:var(--coral-soft);}
.file-drop{border:1.5px dashed var(--line); border-radius:10px; padding:16px; text-align:center; font-size:12.5px; color:var(--muted); cursor:pointer;}
.file-drop:hover{border-color:var(--blue); color:var(--blue-deep);}
.file-drop.has-file{border-color:var(--green); color:#0B7A4B; background:var(--green-soft);}

/* ============ CHART ============ */
.chart-wrap{width:100%; overflow-x:auto;}
.chart-wrap svg{display:block; width:100%; height:auto;}
.chart-legend{display:flex; gap:18px; margin-top:10px; font-size:12px; color:var(--muted);}
.chart-legend span{display:inline-flex; align-items:center; gap:6px;}
.chart-legend i{width:9px; height:9px; border-radius:3px; display:inline-block;}

/* ============ TOAST ============ */
#toastHost{position:fixed; bottom:22px; right:22px; z-index:200; display:flex; flex-direction:column; gap:8px;}
.toast{padding:12px 16px; border-radius:11px; font-size:13px; font-weight:600; box-shadow:0 12px 30px rgba(11,18,32,.15); animation:toastIn .2s ease;}
.toast.ok{background:#fff; color:#0B7A4B; border:1px solid #b9ecd6;}
.toast.err{background:#fff; color:#B91C1C; border:1px solid #f6c6c6;}
@keyframes toastIn{from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:translateY(0);}}

/* ============ RESPONSIVE ============ */
@media (max-width:980px){
  :root{--sidebar-w:0px;}
  #sidebar{
    position:static; width:100%; height:auto; flex-direction:row; align-items:center;
    border-right:none; border-bottom:1px solid var(--line); overflow-x:auto;
  }
  .sidebar-brand{border-bottom:none; border-right:1px solid var(--line); padding:14px 16px;}
  nav.sidebar-nav{flex-direction:row; padding:8px 10px; overflow-x:auto;}
  nav.sidebar-nav a span{white-space:nowrap;}
  .sidebar-foot{border-top:none; border-left:1px solid var(--line);}
  .user-chip .who{display:none;}
  #mainArea{margin-left:0;}
  main.content{padding:20px 16px 48px;}
  .topbar{padding:14px 16px;}
  .grid.cols-2,.grid.cols-3,.grid.cols-4{grid-template-columns:1fr 1fr;}
  .login-hero{display:none;}
  .login-panel{flex:1;}
}
@media (max-width:560px){
  .grid.cols-2,.grid.cols-3,.grid.cols-4{grid-template-columns:1fr;}
  .form-grid{grid-template-columns:1fr;}
}
