:root{--ink:#232a45;--muted:#8a90a8;--line:#e8eaf3;--blue:#4a7cf7;--green:#2fbf7a;--orange:#f59a2c;--purple:#6c4ff0;--red:#ee5a5a;--bg:#f4f5fb}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;font:13px/1.45 'Inter','Segoe UI',Arial,sans-serif;color:var(--ink);background:var(--bg)}
a{color:#4a5fd8}

/* ---------- Layout + sidebar ---------- */
.layout{display:flex;min-height:100vh}
.sidebar{position:sticky;top:0;height:100vh;flex:0 0 230px;background:linear-gradient(180deg,#3d3fc4 0%,#4b3fd0 45%,#5a46dc 100%);color:#fff;padding:22px 14px;display:flex;flex-direction:column}
.brand{display:flex;gap:10px;align-items:center;font-size:19px;font-weight:800;padding:4px 8px 22px;color:#fff;text-decoration:none}
.brand small{display:block;font-size:9px;letter-spacing:1.7px;font-weight:600;color:#cfd0ff}
.brand-symbol{background:#ffffff26;border-radius:10px;padding:7px 9px}
.nav-label{font-size:9px;font-weight:800;letter-spacing:2px;color:#c6caff;margin:14px 10px 7px}
.side-link{display:flex;align-items:center;gap:12px;min-height:42px;padding:10px 13px;margin-bottom:5px;color:#dcdcff;text-decoration:none;font-weight:600;border-radius:10px;transition:.2s}
.side-link:hover{background:#ffffff1f;color:#fff}
.side-link.active{background:linear-gradient(90deg,#4f8cff,#6aa0ff);color:#fff;box-shadow:0 6px 16px rgba(60,120,255,.4)}
.nav-icon{font-size:17px;width:20px;text-align:center}
.sidebar-footer{margin-top:auto;padding:12px;border-radius:12px;background:#ffffff1a;display:flex;gap:10px;align-items:center;font-size:12px}
.sidebar-footer small{display:block;color:#cfd0ff;font-size:11px}
.avatar{width:36px;height:36px;border-radius:50%;display:grid;place-items:center;background:linear-gradient(135deg,#f6b58a,#d9627d);font-weight:700;border:2px solid #fff6;flex:none}

/* ---------- Top bar + content ---------- */
.content{min-width:0;flex:1}
.topbar{min-height:68px;background:#fff;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;padding:10px 26px;gap:15px}
.topbar h1{font-size:21px;margin:0}
.topbar p{font-size:12px;color:var(--muted);margin:2px 0 0}
.top-actions{display:flex;align-items:center;gap:6px}
.top-badge,.badge{border-radius:20px;background:#ecebff;color:#5a46dc;padding:7px 13px;font-weight:700;font-size:12px}
.top-logout{color:#4a5070;text-decoration:none;margin-left:12px;font-weight:600}
.top-logout:hover{color:var(--red)}
.wrap{padding:18px 26px 26px;max-width:none;margin:0}
.hero{display:flex;justify-content:space-between;align-items:center;gap:12px;margin:0 0 16px;flex-wrap:wrap}
.hero h2{font-size:18px;margin:0}
.hero p,.sub{font-size:12px;color:var(--muted);margin:3px 0 8px}

/* ---------- Forms + buttons ---------- */
.filters{display:flex;gap:8px;align-items:end;flex-wrap:wrap}
label{display:block;font-size:10px;color:#6b7391;font-weight:700;letter-spacing:.4px;margin:0 0 4px}
input,select{background:#fff;border:1px solid #dfe2f0;border-radius:9px;padding:8px 11px;color:var(--ink);max-width:100%;font:inherit}
input:focus,select:focus{outline:2px solid #c9d4ff;border-color:#8da4ff}
.filters select,.filters input{height:36px}
.btn,button{background:linear-gradient(100deg,#4f7cf7,#7a5cf0);color:#fff;border:0;border-radius:10px;padding:9px 14px;font-weight:700;font:inherit;font-weight:700;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;box-shadow:0 4px 12px rgba(90,80,230,.25)}
.btn:hover,button:hover{filter:brightness(1.07)}
.btn.green,.secondary{background:linear-gradient(100deg,#25b97e,#3fd0a0);box-shadow:0 4px 12px rgba(40,190,130,.25)}
.btn.alt{background:#344e67;box-shadow:none}
.btn.white{background:#fff;color:#3d4fb8;border:1px solid #dfe2f0;box-shadow:none}

/* ---------- Dashboard grid ---------- */
.compact-stock-grid{display:grid;grid-template-columns:minmax(0,1.6fr) minmax(0,.95fr) minmax(0,.95fr);grid-template-rows:112px 252px 242px;gap:16px;align-items:stretch}
.compact-stock-grid>.metrics{grid-column:1/-1;grid-row:1;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px}
.compact-stock-grid>.primary-panels,.compact-stock-grid>.detail-panels{display:contents}
.compact-stock-grid>.primary-panels>.panel:first-child{grid-column:1;grid-row:2}
.compact-stock-grid>.primary-panels>.panel:nth-child(2){grid-column:2;grid-row:2}
.compact-stock-grid>.detail-panels>.panel:nth-child(2){grid-column:3;grid-row:2}
.compact-stock-grid>#dayComparisonPanel{grid-column:1/3;grid-row:3;margin:0!important}
.compact-stock-grid>.detail-panels>.panel:first-child{grid-column:3;grid-row:3}

/* ---------- Stat cards ---------- */
.metric{min-width:0;position:relative;overflow:hidden;border-radius:14px;padding:16px 16px 10px 78px;background:#fff;box-shadow:0 4px 14px rgba(70,70,140,.08);border:0}
.metric::before{content:'';position:absolute;inset:0;opacity:.14;pointer-events:none;background:linear-gradient(120deg,currentColor,transparent 70%)}
.metric::after{display:none}
.metric.one{color:var(--blue)}.metric.two{color:var(--green)}.metric.three{color:var(--orange)}.metric.four{color:var(--purple)}
.metric-icon{position:absolute;top:20px;left:16px;display:grid;place-items:center;width:48px;height:48px;border-radius:13px;color:#fff;font-size:22px;z-index:1}
.metric.one .metric-icon{background:linear-gradient(135deg,#4a7cf7,#6aa6ff)}
.metric.two .metric-icon{background:linear-gradient(135deg,#2fbf7a,#58dca0)}
.metric.three .metric-icon{background:linear-gradient(135deg,#f59a2c,#ffc062)}
.metric.four .metric-icon{background:linear-gradient(135deg,#6c4ff0,#9a82ff)}
.metric .caption,.metric .number,.metric .unit,.metric .chip{position:relative;z-index:1}
.metric .caption{font-size:12px;color:var(--muted);font-weight:600}
.metric .number{font-size:26px;font-weight:800;color:var(--ink);line-height:1.2;margin-top:3px}
.metric .unit{font-size:10px;color:var(--muted)}
.metric .chip{display:inline-block;margin-top:5px;font-size:10px;background:#ffffffc0;border-radius:20px;padding:3px 9px;font-weight:700;color:#4a5070}

/* ---------- Panels ---------- */
.panel,.card{min-width:0;min-height:0;background:#fff;border:0;border-radius:14px;box-shadow:0 4px 14px rgba(70,70,140,.08);padding:15px 18px;overflow:hidden}
.panel h3,.card h2,.card h3{font-size:14px;margin:0 0 4px}
.panel .sub{margin-bottom:7px}
.split{display:flex;align-items:center;justify-content:space-between;gap:10px}
.legend{display:flex;flex-wrap:wrap;gap:12px;font-size:11px;color:var(--muted)}
.dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:5px}
.chart{width:100%;height:170px;display:block}
#dayComparisonChart{height:150px!important}
.donut-row{height:180px;min-height:0;display:flex;align-items:center;justify-content:center;gap:18px}
.donut{position:relative;width:132px;height:132px;flex:none;border-radius:50%;background:conic-gradient(#5b8cf7 0 var(--hm-pct),#7c4ff0 var(--hm-pct) 100%)}
.donut::after{content:'';position:absolute;inset:30px;border-radius:50%;background:#fff}
.donut-center{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;flex-direction:column;font-weight:800;font-size:20px}
.donut-center span{font-size:10px;color:var(--muted);font-weight:500}
.donut-legend{font-size:12px;color:#4a5070}
.donut-legend div{margin:12px 0}
.donut-legend strong{display:block;margin-left:14px;font-size:17px;color:var(--ink)}

/* ---------- Tables ---------- */
.table-wrap,.scroll{overflow:auto;max-height:165px}
.card .scroll{max-height:none}
table{width:100%;border-collapse:collapse;font-size:12px}
th,td{padding:8px 10px;border-bottom:1px solid #eef0f7;text-align:left}
th{background:#f4f5fc;color:#5b6180;font-weight:700}
tbody tr:hover{background:#f8f9ff}
.empty{color:var(--muted);text-align:center;padding:14px}
.sync-form{display:block}
.sync-form .btn{padding:6px 12px;margin-top:5px!important;font-size:11px}
.sharebar{display:flex;gap:10px;flex-wrap:wrap;margin:16px 0}
.sharebar .btn{min-height:40px;min-width:170px}
.sharebar .btn:nth-child(2){background:linear-gradient(100deg,#25b97e,#3fd0a0)}

/* ---------- Messages + misc ---------- */
.flash{background:#e6f8ef;color:#116947;padding:11px 14px;border-radius:10px;margin-bottom:12px;border:1px solid #c6efdc}
.flash.danger{background:#ffecec;color:#a02828;border-color:#ffd0d0}
.status{border-radius:15px;padding:4px 10px;background:#e3f8ed;color:#0b8a60;font-weight:700;font-size:11px}
.muted,.footer-note{color:var(--muted)}
.footer-note{font-size:11px;margin:10px 0}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px}
.inline{display:flex;gap:12px;align-items:end;flex-wrap:wrap}
.inline>div{min-width:160px}
.inline input,.inline select{width:100%}
.card{padding:22px;margin-bottom:16px}
.card h2{font-size:19px}.card h3{font-size:16px}
details summary{cursor:pointer;color:#425ed8;font-weight:700}

/* ---------- Sign-in page ---------- */
body.guest{min-height:100vh;background:radial-gradient(circle at 15% 20%,#8b6cf5 0,transparent 45%),radial-gradient(circle at 85% 80%,#5aa0f7 0,transparent 45%),linear-gradient(135deg,#5a4fd8,#8e7cf0 50%,#6aa6f5)}
.auth-layout{min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:24px;gap:18px}
.auth-brand{color:#fff;font-size:22px;font-weight:800;text-align:center}
.auth-brand small{display:block;font-size:10px;letter-spacing:2px;font-weight:600;color:#e5e3ff}
.auth-layout main{width:100%;max-width:400px}
.login-card{background:#fff;border-radius:20px;padding:32px 30px;box-shadow:0 25px 70px rgba(30,20,90,.35);text-align:center}
.login-card h2{margin:10px 0 2px;font-size:22px}
.login-card form{text-align:left;margin-top:18px}
.login-card input{width:100%;margin-bottom:12px;height:40px}
.login-icon{width:54px;height:54px;margin:0 auto;border-radius:16px;display:grid;place-items:center;font-size:26px;color:#fff;background:linear-gradient(135deg,#4f7cf7,#7a5cf0)}
.login-foot{font-size:11px;color:var(--muted);margin:18px 0 0}

/* ---------- Responsive ---------- */
@media(min-width:1250px) and (min-height:800px){.compact-stock-grid{grid-template-rows:116px 260px 250px}.chart{height:180px}#dayComparisonChart{height:160px!important}}
@media(max-width:1150px){
 .compact-stock-grid{grid-template-columns:1fr 1fr;grid-template-rows:auto}
 .compact-stock-grid>.metrics{grid-column:1/-1;grid-row:auto}
 .compact-stock-grid>.primary-panels,.compact-stock-grid>.detail-panels{display:contents}
 .compact-stock-grid>.primary-panels>.panel:first-child,.compact-stock-grid>.primary-panels>.panel:nth-child(2),.compact-stock-grid>.detail-panels>.panel:nth-child(2),.compact-stock-grid>#dayComparisonPanel,.compact-stock-grid>.detail-panels>.panel:first-child{grid-column:auto;grid-row:auto}
 .compact-stock-grid>#dayComparisonPanel{grid-column:1/-1}
 .compact-stock-grid .panel{min-height:220px}
}
@media(max-width:750px){
 .layout{display:block}
 .sidebar{position:relative;height:auto;width:100%;padding:12px}
 .sidebar-footer{display:none}
 .content{width:100%}
 .topbar{height:auto;padding:12px 16px}
 .wrap{padding:14px}
 .hero{flex-wrap:wrap}
 .compact-stock-grid{display:block}
 .compact-stock-grid>.metrics{grid-template-columns:repeat(2,minmax(0,1fr))}
 .compact-stock-grid>.primary-panels,.compact-stock-grid>.detail-panels{display:block}
 .compact-stock-grid .panel{margin-top:14px}
 .metric{padding-left:62px}
 .metric-icon{width:38px;height:38px;left:12px;font-size:18px}
}
@media print{.sidebar,.filters,.sharebar,.sync-form{display:none!important}.content{padding:0}.panel,.metric{box-shadow:none!important}}

/* ---------- Time-wise table (Time / Received / Dispatched / Total) ---------- */
table.timetable{border-collapse:separate;border-spacing:0;font-size:12px}
.timetable th,.timetable td{text-align:center;font-weight:700;padding:7px 8px;border-bottom:1px solid #dfe3f2;border-right:1px solid #dfe3f2}
.timetable th:last-child,.timetable td:last-child{border-right:0}
.timetable thead th{position:sticky;top:0;z-index:1;color:#fff;font-size:12.5px;border-bottom:0}
.timetable .th-time{background:#1f2a5a}
.timetable .th-rec{background:#2fbf7a}
.timetable .th-dis{background:#f59a2c}
.timetable tbody tr:nth-child(even){background:#f7f8fd}
.timetable tfoot td{position:sticky;bottom:0;background:#ffe94a;color:#232a45;border-bottom:0;border-top:1px solid #e6cf1c}
.timetable td.empty{font-weight:500}

/* Panels whose table fills the space left under the heading (Total row / Sync button stay visible) */
.panel.flexcol{display:flex;flex-direction:column}
.flexcol .table-wrap{flex:1 1 auto;min-height:0;max-height:none}
.flexcol .sync-form{flex:none;margin-top:6px}
.flexcol .flash{flex:none;margin:6px 0 0}
/* Donut: larger hole so big totals fit */
.donut{width:142px;height:142px}
.donut::after{inset:26px}
.donut-center{font-size:18px}
.donut-center span{font-size:10px}

/* rounded corners drawn on the cells (overflow:hidden on the table would break the sticky Total row) */
.timetable th:first-child{border-top-left-radius:10px}
.timetable th:last-child{border-top-right-radius:10px}
.timetable tfoot td:first-child{border-bottom-left-radius:10px}
.timetable tfoot td:last-child{border-bottom-right-radius:10px}
.timetable td:first-child,.timetable th:first-child{border-left:1px solid #cfd5ea}
.timetable td:last-child,.timetable th:last-child{border-right:1px solid #cfd5ea}

/* FA dashboard: accommodate three categories and longer quantities. */
:root{--fa:#e3a32f}
.compact-stock-grid{grid-template-rows:minmax(112px,auto) minmax(300px,auto) minmax(270px,auto)}
.compact-stock-grid>.metrics{grid-auto-rows:minmax(112px,auto)}
.metric .number{font-size:clamp(19px,1.9vw,28px);overflow-wrap:anywhere}
.metric .caption{overflow-wrap:anywhere}
.donut-row{height:auto;min-height:180px;display:flex;flex-wrap:wrap;gap:12px;align-items:center;align-content:center}
.donut{width:132px;height:132px;background:#e8ecf5}
.donut::after{inset:24px}
.donut-center{font-size:17px;padding:0 24px;text-align:center;overflow-wrap:anywhere}
.donut-center span{font-size:9px}
.donut-legend{flex:1 1 110px;min-width:0;max-width:100%;font-size:11px;overflow-wrap:anywhere}
.donut-legend div{margin:8px 0}
.donut-legend strong{margin-left:14px;font-size:16px;font-variant-numeric:tabular-nums}
.compact-stock-grid>.primary-panels>.panel:nth-child(2){container-type:inline-size}
@container(max-width:260px){
 .donut-row{flex-direction:column;gap:8px}
 .donut{width:120px;height:120px}
 .donut-legend{flex:0 0 auto;width:100%;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
 .donut-legend div{margin:0;font-size:10px}
 .donut-legend strong{margin-left:0;font-size:14px}
}
.compact-stock-grid .split{flex-wrap:wrap}
.compact-stock-grid .panel.flexcol>.table-wrap{min-height:100px}
.table-wrap{overscroll-behavior-x:contain}
th,td{font-variant-numeric:tabular-nums}
.topbar-title,.top-actions{min-width:0}
.sidebar-footer strong{overflow-wrap:anywhere}
a:focus-visible,button:focus-visible,select:focus-visible,input:focus-visible{outline:3px solid #91a9ff;outline-offset:3px}
@media(min-width:1250px) and (min-height:800px){
 .compact-stock-grid{grid-template-rows:minmax(116px,auto) minmax(300px,auto) minmax(280px,auto)}
}
@media(max-width:1150px){
 .compact-stock-grid{grid-template-rows:auto}
 .compact-stock-grid>.metrics{grid-template-columns:repeat(2,minmax(0,1fr))}
 .compact-stock-grid .panel{min-height:240px}
 .compact-stock-grid .panel.flexcol>.table-wrap{max-height:290px;flex:1 1 auto}
}
@media(max-width:750px){
 .topbar{flex-wrap:wrap;gap:10px}
 .top-actions{flex-wrap:wrap}
 .filters{width:100%}
 .filters>div{flex:1 1 140px;min-width:0}
 .filters select,.filters input{width:100%}
 .compact-stock-grid>.metrics{gap:10px}
 .metric{padding-top:14px;padding-bottom:12px}
 .metric .number{font-size:23px}
 .compact-stock-grid .panel{min-height:0}
 .compact-stock-grid .panel.flexcol>.table-wrap{max-height:320px}
 .donut-row{min-height:170px}
 .sharebar .btn{flex:1 1 180px;min-width:0}
}
@media(max-width:380px){
 .compact-stock-grid>.metrics{grid-template-columns:minmax(0,1fr)}
 .topbar h1{font-size:18px}
}
@media print{
 .topbar .top-actions{display:none!important}
 .compact-stock-grid{display:block}
 .compact-stock-grid>.metrics{display:grid;grid-template-columns:repeat(4,minmax(0,1fr))}
 .compact-stock-grid>.primary-panels,.compact-stock-grid>.detail-panels{display:block}
 .compact-stock-grid .panel{margin-top:14px;break-inside:avoid}
 .panel.flexcol>.table-wrap,.table-wrap{max-height:none!important;overflow:visible}
}
