:root{
  --navy:#0f2942; --navy-light:#173a5e; --blue:#2563eb; --blue-light:#dbeafe;
  --grey:#64748b; --grey-light:#f1f5f9; --border:#e2e8f0;
  --green:#16a34a; --green-light:#dcfce7;
  --red:#dc2626; --red-light:#fee2e2;
  --orange:#ea580c; --orange-light:#ffedd5;
  --bg:#f6f8fb; --card:#ffffff; --text:#1e293b; --text-muted:#64748b;
  --radius:10px; --shadow:0 1px 3px rgba(15,41,66,.08),0 1px 2px rgba(15,41,66,.06);
  --sidebar-w:250px;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;height:100%;}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg); color:var(--text); font-size:14px; line-height:1.5;
}
a{color:var(--blue); text-decoration:none;}
button{font-family:inherit; cursor:pointer;}
input,select,textarea{font-family:inherit; font-size:14px;}
h1,h2,h3,h4{margin:0 0 4px; font-weight:600; color:var(--navy);}
::-webkit-scrollbar{width:10px; height:10px;}
::-webkit-scrollbar-thumb{background:#cbd5e1; border-radius:6px;}

/* ---------- Auth screen ---------- */
.auth-wrap{min-height:100vh; display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg,var(--navy) 0%, #1e4a75 100%);}
.auth-card{background:#fff; width:400px; max-width:92vw; border-radius:14px; padding:36px 32px; box-shadow:0 20px 50px rgba(0,0,0,.25);}
.auth-card h1{font-size:20px; text-align:center; margin-bottom:2px;}
.auth-card p.sub{text-align:center; color:var(--text-muted); margin:0 0 24px; font-size:13px;}
.field{margin-bottom:16px;}
.field label{display:block; font-size:12.5px; font-weight:600; color:var(--navy); margin-bottom:6px;}
.field input,.field select,.field textarea{
  width:100%; padding:9px 12px; border:1px solid var(--border); border-radius:8px; background:#fff; color:var(--text);
}
.field input:focus,.field select:focus,.field textarea:focus{outline:2px solid var(--blue); outline-offset:0; border-color:var(--blue);}
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding:9px 16px; border-radius:8px; border:1px solid transparent; font-weight:600; font-size:13.5px;
  background:var(--blue); color:#fff; transition:background .15s;
}
.btn:hover{background:#1d4ed8;}
.btn.block{width:100%;}
.btn.secondary{background:#fff; color:var(--navy); border-color:var(--border);}
.btn.secondary:hover{background:var(--grey-light);}
.btn.danger{background:var(--red);}
.btn.danger:hover{background:#b91c1c;}
.btn.sm{padding:5px 10px; font-size:12.5px;}
.btn:disabled{opacity:.5; cursor:not-allowed;}
.error-banner{background:var(--red-light); color:#991b1b; padding:9px 12px; border-radius:8px; font-size:13px; margin-bottom:14px;}
.info-banner{background:var(--blue-light); color:#1e3a8a; padding:9px 12px; border-radius:8px; font-size:13px; margin-bottom:14px;}

/* ---------- App shell ---------- */
.app-shell{display:flex; min-height:100vh;}
.sidebar{
  width:var(--sidebar-w); background:var(--navy); color:#cfe0f0; flex-shrink:0;
  display:flex; flex-direction:column; position:fixed; top:0; bottom:0; left:0; overflow-y:auto; z-index:20;
}
.sidebar .brand{padding:20px 18px; font-weight:700; color:#fff; font-size:15px; border-bottom:1px solid rgba(255,255,255,.08); line-height:1.3;}
.sidebar .brand span{display:block; font-weight:400; font-size:11px; color:#93b3d1; margin-top:2px;}
.nav-group{padding:10px 0;}
.nav-label{padding:10px 18px 4px; font-size:10.5px; text-transform:uppercase; letter-spacing:.06em; color:#6f92b5;}
.nav-item{
  display:flex; align-items:center; gap:10px; padding:9px 18px; color:#cfe0f0; font-size:13.5px; cursor:pointer;
  border-left:3px solid transparent;
}
.nav-item:hover{background:rgba(255,255,255,.06);}
.nav-item.active{background:rgba(37,99,235,.25); color:#fff; border-left-color:var(--blue);}
.nav-item.sub{padding-left:34px; font-size:13px;}
.main{margin-left:var(--sidebar-w); flex:1; min-width:0; display:flex; flex-direction:column;}
.topbar{
  background:#fff; border-bottom:1px solid var(--border); padding:12px 24px; display:flex; align-items:center;
  justify-content:space-between; position:sticky; top:0; z-index:10;
}
.topbar .search{flex:1; max-width:420px;}
.topbar .search input{width:100%; padding:8px 12px; border:1px solid var(--border); border-radius:8px;}
.topbar .user-menu{display:flex; align-items:center; gap:12px;}
.avatar{width:34px; height:34px; border-radius:50%; background:var(--blue); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px;}
.content{padding:22px 26px 60px; flex:1;}

/* ---------- Cards / KPIs ---------- */
.page-header{display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; flex-wrap:wrap; gap:10px;}
.kpi-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:22px;}
.kpi-card{background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:16px 18px; border-top:3px solid var(--blue);}
.kpi-card .label{font-size:11.5px; color:var(--text-muted); text-transform:uppercase; letter-spacing:.04em; font-weight:600;}
.kpi-card .value{font-size:22px; font-weight:700; color:var(--navy); margin-top:6px;}
.kpi-card.green{border-top-color:var(--green);} .kpi-card.red{border-top-color:var(--red);}
.kpi-card.orange{border-top-color:var(--orange);} .kpi-card.grey{border-top-color:var(--grey);}

.chart-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(380px,1fr)); gap:16px; margin-bottom:20px;}
.card{background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:16px 18px;}
.card h3{font-size:13.5px; margin-bottom:12px; color:var(--navy);}
.card canvas{max-height:280px;}
.list-card table{width:100%;}

/* ---------- Filters ---------- */
.filter-bar{display:flex; flex-wrap:wrap; gap:10px; margin-bottom:16px; align-items:flex-end;}
.filter-bar .field{margin:0; min-width:140px;}
.filter-bar .field label{font-size:11px; margin-bottom:3px;}
.filter-bar .field input,.filter-bar .field select{padding:7px 10px;}

/* ---------- Table ---------- */
.table-wrap{background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); overflow-x:auto;}
table{border-collapse:collapse; width:100%; font-size:13.2px;}
thead th{
  background:var(--grey-light); text-align:left; padding:10px 14px; font-weight:600; color:var(--navy);
  white-space:nowrap; border-bottom:1px solid var(--border); position:sticky; top:0;
}
tbody td{padding:10px 14px; border-bottom:1px solid var(--border); white-space:nowrap;}
tbody tr:hover{background:#f8fafc;}
tbody tr{cursor:pointer;}
.table-toolbar{display:flex; justify-content:space-between; align-items:center; padding:12px 14px; flex-wrap:wrap; gap:10px;}
.pagination{display:flex; gap:6px; align-items:center; padding:12px 14px; justify-content:flex-end;}

/* ---------- Badges ---------- */
.badge{display:inline-block; padding:3px 10px; border-radius:20px; font-size:11.5px; font-weight:700;}
.badge.status-active{background:var(--blue-light); color:#1d4ed8;}
.badge.status-passive{background:#e2e8f0; color:#475569;}
.badge.status-won{background:var(--green-light); color:#15803d;}
.badge.status-lost{background:var(--red-light); color:#b91c1c;}
.badge.status-on-hold{background:var(--orange-light); color:#c2410c;}
.badge.status-cancelled{background:#f1f5f9; color:#64748b;}
.badge.priority-high,.badge.priority-critical,.badge.priority-urgent{background:var(--red-light); color:#b91c1c;}
.badge.priority-medium{background:var(--orange-light); color:#c2410c;}
.badge.priority-low{background:var(--green-light); color:#15803d;}
.badge.task-overdue{background:var(--red-light); color:#b91c1c;}
.badge.task-open{background:var(--blue-light); color:#1d4ed8;}
.badge.task-in-progress{background:var(--orange-light); color:#c2410c;}
.badge.task-completed{background:var(--green-light); color:#15803d;}
.badge.task-waiting{background:#f1f5f9; color:#475569;}

/* ---------- Tabs ---------- */
.tabs{display:flex; gap:2px; border-bottom:1px solid var(--border); margin-bottom:18px; overflow-x:auto;}
.tab{padding:10px 16px; font-size:13px; font-weight:600; color:var(--text-muted); border-bottom:2px solid transparent; white-space:nowrap; cursor:pointer;}
.tab.active{color:var(--blue); border-bottom-color:var(--blue);}

/* ---------- Modal ---------- */
.modal-backdrop{position:fixed; inset:0; background:rgba(15,23,42,.55); display:flex; align-items:flex-start; justify-content:center; z-index:100; padding:4vh 16px; overflow-y:auto;}
.modal{background:#fff; border-radius:14px; width:720px; max-width:96vw; box-shadow:0 25px 60px rgba(0,0,0,.35);}
.modal.narrow{width:480px;}
.modal.wide{width:960px;}
.modal-header{display:flex; align-items:center; justify-content:space-between; padding:16px 22px; border-bottom:1px solid var(--border);}
.modal-header h2{font-size:16px; margin:0;}
.modal-body{padding:20px 22px; max-height:70vh; overflow-y:auto;}
.modal-footer{padding:14px 22px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:10px;}
.close-x{background:none; border:none; font-size:20px; color:var(--text-muted); line-height:1;}
.form-grid{display:grid; grid-template-columns:1fr 1fr; gap:14px 16px;}
.form-grid .full{grid-column:1/-1;}
.checkbox-row{display:flex; align-items:center; gap:8px;}
.checkbox-row input{width:auto;}
.tech-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(160px,1fr)); gap:8px; max-height:300px; overflow-y:auto; padding:4px;}
.tech-pill{display:flex; align-items:center; gap:6px; padding:6px 10px; border:1px solid var(--border); border-radius:8px; font-size:12.5px;}
.tech-pill input{width:auto;}

/* ---------- Timeline ---------- */
.timeline{position:relative; padding-left:26px;}
.timeline::before{content:""; position:absolute; left:7px; top:6px; bottom:6px; width:2px; background:var(--border);}
.timeline-item{position:relative; padding-bottom:22px;}
.timeline-item::before{content:""; position:absolute; left:-26px; top:4px; width:12px; height:12px; border-radius:50%; background:var(--blue); border:2px solid #fff; box-shadow:0 0 0 2px var(--blue);}
.timeline-item .t-head{font-weight:700; color:var(--navy); font-size:13.5px;}
.timeline-item .t-date{color:var(--text-muted); font-size:12px; margin-bottom:4px;}
.timeline-item .t-body{background:var(--grey-light); border-radius:8px; padding:10px 12px; font-size:13px;}

/* ---------- Misc ---------- */
.empty-state{text-align:center; padding:50px 20px; color:var(--text-muted);}
.section-title{font-size:14px; font-weight:700; color:var(--navy); margin:22px 0 10px;}
.section-title:first-child{margin-top:0;}
.tag-list{display:flex; flex-wrap:wrap; gap:6px;}
.tag{background:var(--blue-light); color:#1d4ed8; padding:3px 10px; border-radius:20px; font-size:11.5px; font-weight:600;}
.toast-wrap{position:fixed; top:20px; right:20px; z-index:200; display:flex; flex-direction:column; gap:8px;}
.toast{background:var(--navy); color:#fff; padding:10px 16px; border-radius:8px; font-size:13px; box-shadow:var(--shadow); min-width:220px;}
.toast.error{background:var(--red);}
.toast.success{background:var(--green);}
.tooltip-icon{color:var(--text-muted); font-size:11px; cursor:help;}
.mini-table td, .mini-table th{padding:6px 10px; font-size:12.5px;}
.text-muted{color:var(--text-muted);}
.spinner{width:22px; height:22px; border:3px solid var(--border); border-top-color:var(--blue); border-radius:50%; animation:spin .7s linear infinite; margin:30px auto;}
@keyframes spin{to{transform:rotate(360deg);}}
.hamburger{display:none;}
@media(max-width:960px){
  .sidebar{transform:translateX(-100%); transition:transform .2s; box-shadow:0 0 30px rgba(0,0,0,.3);}
  .sidebar.open{transform:translateX(0);}
  .main{margin-left:0;}
  .hamburger{display:block; background:none; border:none; font-size:20px; color:var(--navy); margin-right:10px;}
  .form-grid{grid-template-columns:1fr;}
}
