:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #6b7a8c;
  --line: #e3e8ef;
  --brand: #1d5fd1;
  --brand-dark: #17499f;
  --green: #178a4c;
  --amber: #b97a0a;
  --red: #c73434;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 14.5px; }
.center-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; color: var(--muted); }

/* Layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 215px; background: #14243c; color: #cfd9e6; flex-shrink: 0; display: flex; flex-direction: column; }
.sidebar .brand { padding: 18px 16px; font-weight: 700; color: #fff; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand small { display: block; font-weight: 400; color: #8fa3bd; font-size: 11.5px; margin-top: 2px; }
.sidebar nav { flex: 1; padding: 8px 0; }
.sidebar nav a { display: block; padding: 10px 16px; color: #cfd9e6; text-decoration: none; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: rgba(255,255,255,.1); border-left-color: var(--brand); color: #fff; }
.sidebar .foot { padding: 12px 16px; font-size: 12.5px; color: #8fa3bd; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar .foot a { color: #cfd9e6; text-decoration: none; }
.main { flex: 1; padding: 22px 26px; max-width: 1200px; }
h1 { font-size: 21px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 20px 0 10px; }

/* Cards / tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: #f8fafc; }
td.num, th.num { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 10px; text-align: center; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.b-pending { background: #fff4d6; color: #8a6100; }
.b-accepted, .b-active, .b-paid, .b-received { background: #ddf3e4; color: var(--green); }
.b-rejected, .b-cancelled, .b-inactive, .b-overdue { background: #fde3e3; color: var(--red); }
.b-converted, .b-issued { background: #dfe9fb; color: var(--brand-dark); }
.b-partial, .b-duesoon { background: #fdeed6; color: var(--amber); }
.b-unpaid, .b-closed { background: #e8ecf1; color: #55657a; }

/* Buttons / forms */
.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font-size: 13.5px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover { background: #eef4ff; }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: #fdf0f0; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #c9d3e0; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd2f7; border-color: var(--brand); }
label { display: block; font-size: 12.5px; font-weight: 600; color: #405063; margin: 10px 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.inline-input { width: auto; }
.muted { color: var(--muted); }
.right { text-align: right; }
a.link { color: var(--brand); text-decoration: none; cursor: pointer; }
a.link:hover { text-decoration: underline; }

/* Modal */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(15,25,40,.5); display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; padding: 20px 22px 22px; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 950px; }
.modal h2 { margin: 0 0 6px; font-size: 17px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Items editor */
.items-table input { padding: 6px 8px; }
.items-table td { padding: 4px 4px; border-bottom: none; }
.items-table th { padding: 4px 6px; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 99; font-size: 13.5px; }
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* OCR drop zone */
.dropzone { border: 2px dashed #b9c6d8; border-radius: 10px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 8px; }
.dropzone.drag { border-color: var(--brand); background: #eef4ff; color: var(--brand); }
.ocr-status { font-size: 13px; color: var(--amber); margin: 6px 0; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 360px; box-shadow: 0 10px 30px rgba(20,36,60,.08); }
.login-box h1 { font-size: 19px; }

/* Print PO */
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; width: 100%; }
  .sidebar, .toolbar, .btn { display: none !important; }
}
#print-area { background: #fff; color: #000; padding: 30px 34px; font-size: 13px; }
#print-area .po-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
#print-area .po-title { font-size: 24px; font-weight: 800; letter-spacing: .04em; text-align: right; }
#print-area img.logo { max-height: 70px; max-width: 220px; }
#print-area table { margin-top: 12px; }
#print-area th { border-bottom: 2px solid #000; color: #000; }
#print-area td { border-bottom: 1px solid #ccc; }
#print-area .totals td { border: none; padding: 3px 10px; }
#print-area .sign { display: flex; justify-content: space-between; margin-top: 70px; }
#print-area .sign div { width: 40%; border-top: 1px solid #000; padding-top: 6px; text-align: center; font-size: 12px; }

@media (max-width: 800px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .main { padding: 14px; }
}
