:root {
  --navy:#16345a;
  --sky:#2f89cc;
  --gold:#caa600;
  --bg:#eef2f6;
  --text:#1d2430;
  --white:#fff;
  --line:#d8dee7;
  --danger:#cf3f3f;
  --success:#1f8b4c;
  --shadow:0 10px 30px rgba(15,30,50,.08);
  --radius:18px;
}

*{box-sizing:border-box}
html{font-size:16px;-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{margin:0;font-family:Tahoma,Arial,sans-serif;background:var(--bg);color:var(--text);line-height:1.5}
body.nav-open{overflow:hidden}
a{text-decoration:none;color:inherit}
img{max-width:100%;height:auto}
button,input,select,textarea{font:inherit}

.app-shell{min-height:100vh}
.topbar{
  position:sticky;top:0;z-index:1100;
  background:linear-gradient(180deg,#173a63 0%,#16345a 100%);color:#fff;display:flex;justify-content:space-between;align-items:center;
  padding:14px 22px;gap:18px;box-shadow:0 8px 24px rgba(8,20,38,.18)
}
.topbar-left{display:flex;align-items:center;gap:14px;min-width:0;flex:1 1 auto}
.brand-wrap{display:flex;align-items:center;gap:14px;min-width:0;flex:1 1 auto}
.brand-logo{width:52px;height:52px;object-fit:contain;background:#fff;border-radius:12px;padding:4px;flex:0 0 auto;box-shadow:0 10px 20px rgba(10,20,35,.16)}
.brand-text{min-width:0}
.brand-pill{display:inline-block;background:#f47d22;color:#fff;font-weight:700;padding:8px 14px;border-radius:999px;margin-bottom:4px;font-size:14px;line-height:1.2;box-shadow:0 6px 14px rgba(244,125,34,.24)}
.brand-title{font-size:clamp(18px,2vw,28px);font-weight:700;line-height:1.15;word-break:normal;overflow-wrap:break-word;max-width:100%}
.brand-subtitle{font-size:12px;color:rgba(255,255,255,.78);margin-top:4px}
.topbar-right{display:flex;align-items:center;gap:12px;flex-wrap:wrap;justify-content:flex-end;flex:0 1 auto}
.user-badge{padding:10px 14px;border-radius:16px;background:rgba(255,255,255,.1);backdrop-filter:blur(8px);font-size:14px;display:flex;align-items:center;gap:6px;flex-wrap:wrap;border:1px solid rgba(255,255,255,.08)}
.user-badge-label{color:rgba(255,255,255,.78)}
.muted-light{color:rgba(255,255,255,.8)}

.nav-toggle{
  display:none;align-items:center;justify-content:center;flex-direction:column;gap:4px;
  width:46px;height:46px;border:1px solid rgba(255,255,255,.2);background:rgba(255,255,255,.08);
  border-radius:14px;cursor:pointer;flex:0 0 auto
}
.nav-toggle span{display:block;width:20px;height:2px;background:#fff;border-radius:2px}
.sidebar-backdrop{display:none}

.layout{display:flex;min-height:calc(100vh - 84px)}
.sidebar{
  width:260px;flex:0 0 260px;background:#fff;border-right:1px solid var(--line);padding:18px;
  display:flex;flex-direction:column;gap:16px;position:sticky;top:84px;height:calc(100vh - 84px);overflow:auto
}
.sidebar-head{padding:4px 6px 0}
.sidebar-title{font-size:18px;font-weight:700;color:var(--navy)}
.sidebar-nav{display:flex;flex-direction:column;gap:10px}
.sidebar a{
  padding:13px 14px;border:1px solid var(--line);border-radius:14px;color:var(--sky);font-weight:700;background:#fff;
  transition:all .2s ease;box-shadow:0 1px 2px rgba(16,24,40,.03)
}
.sidebar a:hover{border-color:#f8a24f;box-shadow:0 0 0 2px #fee7d0 inset;transform:translateY(-1px)}
.sidebar a.active{background:linear-gradient(180deg,#f3f9ff,#e8f2fb);border-color:#b8d6ee;color:var(--navy);box-shadow:0 0 0 2px #dcecf9 inset}

.content{flex:1;min-width:0;padding:24px}
.page-header{display:flex;justify-content:space-between;align-items:center;gap:16px;margin-bottom:18px;flex-wrap:wrap}
.page-header h1{margin:0;font-size:clamp(24px,3.2vw,34px);line-height:1.2}
.card{background:#fff;border:1px solid var(--line);border-radius:var(--radius);padding:20px;margin-bottom:18px;box-shadow:0 2px 8px rgba(15,30,50,.04)}
.grid{display:grid;gap:18px}
.grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}
.grid-4{grid-template-columns:repeat(4,minmax(0,1fr))}

label{display:block;font-weight:700;margin-bottom:6px}
input,select,textarea{
  width:100%;min-width:0;padding:12px 14px;border:1px solid #cfd7e4;border-radius:12px;background:#fff;font-size:16px;
  transition:border-color .2s ease, box-shadow .2s ease
}
input:focus,select:focus,textarea:focus{outline:none;border-color:#67a9db;box-shadow:0 0 0 4px rgba(47,137,204,.12)}
textarea{min-height:100px;resize:vertical}

.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;padding:11px 16px;border-radius:12px;border:none;
  cursor:pointer;font-weight:700;white-space:nowrap;transition:transform .15s ease, box-shadow .15s ease, opacity .15s ease
}
.btn:hover{transform:translateY(-1px);box-shadow:0 8px 18px rgba(24,39,75,.12)}
.btn-primary{background:var(--sky);color:#fff}
.btn-gold{background:var(--gold);color:#fff}
.btn-danger{background:var(--danger);color:#fff}
.btn-outline{border:1px solid rgba(255,255,255,.78);color:#fff;background:transparent}
.btn-sm{padding:7px 11px;border-radius:10px;font-size:14px}

.table-wrap{width:100%;overflow:auto;-webkit-overflow-scrolling:touch}
table{width:100%;border-collapse:collapse;background:#fff}
th,td{border:1px solid var(--line);padding:11px;vertical-align:top}
th{background:#f6f8fb;text-align:left;white-space:nowrap}
td{word-break:break-word}
.table-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:flex-start}
.muted{color:#667084}
.alert{padding:14px 16px;border-radius:14px;margin-bottom:14px}
.alert.success{background:#eaf8ef;color:#166534}
.alert.error{background:#fdecec;color:#9f1239}
.kpi{padding:18px;border-radius:18px;background:#fff;border:1px solid var(--line)}
.kpi .value{font-size:clamp(28px,4vw,34px);font-weight:700;margin-top:8px;word-break:break-word}

.login-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px;background:linear-gradient(140deg,#f1f3f7,#e8edf4)}
.login-card{width:min(720px,96vw);background:#fff;border-radius:22px;border:1px solid var(--line);padding:28px;box-shadow:var(--shadow)}
.center{text-align:center}
.mb-2{margin-bottom:12px}
.mb-3{margin-bottom:18px}
.flex{display:flex;gap:12px;align-items:center;flex-wrap:wrap}
.justify-between{justify-content:space-between}
.text-right{text-align:right}

.print-sheet{max-width:980px;margin:16px auto;background:#fff;padding:24px;border:1px solid #222}
.doc-head{display:flex;justify-content:space-between;gap:20px;border-bottom:3px solid #1c2540;padding-bottom:12px;margin-bottom:12px}
.doc-company{display:flex;gap:14px}
.doc-company img{width:92px;height:92px;object-fit:contain}
.doc-box{border:2px solid #1c2540;padding:14px;min-width:360px}
.doc-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:14px}
.doc-sign{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:18px}

.bar-chart{display:flex;align-items:flex-end;gap:12px;height:250px;padding-top:20px;overflow-x:auto;overflow-y:hidden}
.bar-col{flex:1;min-width:42px;text-align:center}
.bar{width:100%;border-radius:12px 12px 0 0;background:var(--sky)}
.bar.expense{background:var(--gold)}

@media (max-width:1200px){
  .grid-4{grid-template-columns:repeat(2,minmax(0,1fr))}
}

@media (max-width:980px){
  .topbar{padding:14px 16px;align-items:flex-start;flex-wrap:wrap;gap:14px}
  .topbar-left{width:100%}
  .topbar-right{width:100%;justify-content:space-between}
  .nav-toggle{display:inline-flex}
  .sidebar-backdrop{
    display:block;position:fixed;inset:0;background:rgba(15,23,42,.45);opacity:0;pointer-events:none;transition:opacity .2s ease;z-index:1090
  }
  body.nav-open .sidebar-backdrop{opacity:1;pointer-events:auto}
  .layout{display:block;min-height:auto}
  .sidebar{
    position:fixed;top:0;left:0;height:100vh;width:min(320px,86vw);max-width:100%;transform:translateX(-102%);
    transition:transform .24s ease;z-index:1101;border-right:none;box-shadow:var(--shadow);padding-top:86px
  }
  body.nav-open .sidebar{transform:translateX(0)}
  .content{padding:18px 16px 24px}
  .grid-2,.grid-3,.doc-grid,.doc-sign{grid-template-columns:1fr}
  .grid-4{grid-template-columns:repeat(2,minmax(0,1fr))}
  .page-header{align-items:flex-start}
  .flex{align-items:stretch}
  .flex .btn{width:100%}
  .brand-wrap{align-items:center}
  .brand-logo{width:46px;height:46px}
}

@media (max-width:768px){
  .topbar{gap:12px}
  .brand-pill{font-size:12px;padding:6px 10px;margin-bottom:3px}
  .brand-title{font-size:18px}
  .brand-subtitle{display:none}
  .user-badge{flex:1 1 auto;border-radius:14px;padding:10px 12px}
  .topbar-right{align-items:stretch}
  .topbar-right .btn{width:auto;min-width:120px}
  .card{padding:16px;border-radius:16px}
  input,select,textarea{padding:11px 12px;font-size:16px}
  th,td{padding:10px}
  .bar-chart{height:220px;gap:10px}
  .bar-col{min-width:34px}
  .doc-box{min-width:0}
  .doc-head,.doc-company{flex-direction:column}
}


@media (max-width:560px){
  .topbar{padding:12px 12px 14px;border-bottom-left-radius:18px;border-bottom-right-radius:18px}
  .topbar-left{gap:10px}
  .brand-wrap{gap:10px}
  .brand-logo{width:40px;height:40px;border-radius:10px}
  .brand-pill{display:none}
  .brand-title{font-size:16px;max-width:170px}
  .user-badge{width:100%;font-size:13px;gap:4px}
  .muted-light{display:none}
  .topbar-right{gap:10px}
  .topbar-right .btn{width:100%;min-width:0;padding:10px 12px;border-radius:12px}
  .content{padding:16px 12px 20px}
  .page-header h1{font-size:30px}
  .grid{gap:14px}
  .grid-4{grid-template-columns:1fr}
  .kpi{padding:14px 16px;border-radius:16px}
  .kpi .value{font-size:clamp(22px,7vw,30px);margin-top:4px}
  .nav-toggle{width:42px;height:42px;border-radius:12px}
}

@media screen and (max-width:860px){
  table,tbody,tr,td,th{font-size:14px}
  table{border:0}
  table tr:first-child{display:none}
  table tbody, table{display:block}
  table tr{
    display:block;margin-bottom:12px;border:1px solid var(--line);border-radius:16px;background:#fff;overflow:hidden;box-shadow:0 1px 3px rgba(15,23,42,.04)
  }
  table td{
    display:grid;grid-template-columns:minmax(88px,110px) minmax(0,1fr);gap:10px;align-items:start;
    border-left:0;border-right:0;border-top:0;padding:10px 12px;text-align:left!important
  }
  table td:last-child{border-bottom:0}
  table td::before{content:attr(data-label);font-weight:700;color:var(--navy)}
  .table-actions{display:flex;flex-wrap:wrap;gap:8px}
  .table-actions .btn{flex:1 1 calc(50% - 8px);min-width:120px}
  #items-table tr, #inv-items tr{padding:4px 0}
  #items-table td, #inv-items td{grid-template-columns:1fr}
  #items-table td::before, #inv-items td::before{margin-bottom:4px}
  .kpi{padding:16px}
  .login-card{padding:22px 18px}
}

@media print{
  .no-print,.topbar,.sidebar,.sidebar-backdrop,.nav-toggle{display:none!important}
  body{background:#fff}
  .content{padding:0}
  .print-sheet{border:none;margin:0;max-width:none;padding:0}
}

.btn-success{background:var(--success);color:#fff}
.btn-outline-dark{color:#16345a!important;border:1px solid #16345a;background:#fff}
.btn-disabled{pointer-events:none;opacity:1}
.btn-block{width:100%}

.status-badge{
  display:inline-flex;align-items:center;justify-content:center;padding:6px 10px;border-radius:999px;
  font-size:13px;font-weight:700;line-height:1.2;border:1px solid transparent
}
.status-paid{background:#eaf8ef;color:#166534;border-color:#b7e4c7}
.status-partial{background:#fff7e8;color:#b45309;border-color:#f7d9a7}
.status-overdue{background:#fff1f2;color:#b42318;border-color:#f4c7cc}
.status-sent{background:#eef4ff;color:#1d4ed8;border-color:#c7d7fe}
.stock-ok{background:#eaf8ef;color:#166534;border-color:#b7e4c7}
.stock-low{background:#fff1e8;color:#c2410c;border-color:#fdcba4}

.settings-upload-grid{align-items:start}
.settings-upload-card{display:flex;flex-direction:column;gap:10px}
.settings-preview-box{
  min-height:140px;padding:14px;border:1px dashed #cfd7e4;border-radius:16px;background:#f8fbff;
  display:flex;align-items:center;justify-content:center;text-align:center
}
.settings-preview-box img{max-height:140px;object-fit:contain}

.section-header{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:14px;flex-wrap:wrap}
.section-header h2{margin:0;font-size:24px;line-height:1.2}
.page-header-inline{align-items:center}

.stock-layout{display:grid;grid-template-columns:minmax(0,1.45fr) minmax(320px,0.95fr);gap:18px;align-items:start}
.stock-main,.stock-side{display:flex;flex-direction:column;gap:18px;min-width:0}
.stock-image-box{display:flex;flex-direction:column;gap:10px;margin-bottom:14px}
.thumb{display:block;border:1px solid var(--line);border-radius:12px;background:#fff;object-fit:cover}
.thumb-sm{width:54px;height:54px}
.thumb-lg{width:120px;height:120px}
.thumb-empty{display:flex;align-items:center;justify-content:center;color:#98a2b3;background:#f8fafc}

@media (max-width:1200px){
  .stock-layout{grid-template-columns:1fr}
}

@media (max-width:860px){
  .status-badge{font-size:12px}
  .section-header h2{font-size:20px}
}


.totals-grid input[readonly]{background:#f8fbff;font-weight:700}
.checkbox-label{display:flex;align-items:center;gap:10px;min-height:44px;margin-bottom:8px;cursor:pointer}
.checkbox-label input[type="checkbox"]{width:18px;height:18px;margin:0}
.print-item-media{width:88px;text-align:center}
.doc-item-thumb{width:64px;height:64px;object-fit:cover;border:1px solid var(--line);border-radius:10px;background:#fff;display:inline-block}
@media (max-width:860px){
  .checkbox-label{min-height:auto}
  .print-item-media{width:auto}
  .doc-item-thumb{width:54px;height:54px}
}
