* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f2f5f8;
  --panel: #ffffff;
  --border: #d7dee6;
  --text: #1e2b38;
  --muted: #64748b;
  --accent: #1668b0;
  --accent-dark: #0f4d85;
  --green: #1e7f3c;
  --red: #b3261e;
  --amber: #92600a;
  --head: #e8eef4;
}
body { font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
#app { display: flex; min-height: 100vh; }

/* sidebar */
#sidebar { width: 210px; background: #16283a; color: #cfd8e3; flex-shrink: 0; display: flex; flex-direction: column; }
#sidebar .brand { padding: 16px 14px; font-weight: 700; font-size: 15px; color: #fff; border-bottom: 1px solid #24384d; line-height: 1.3; }
#sidebar .brand small { display: block; font-weight: 400; color: #8fa3b8; font-size: 11px; }
#sidebar nav { flex: 1; padding: 8px 0; overflow-y: auto; }
#sidebar a { display: block; padding: 9px 16px; color: #cfd8e3; text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent; }
#sidebar a:hover { background: #1d3348; color: #fff; }
#sidebar a.active { background: #0f4d85; color: #fff; border-left-color: #5bc0ff; }
#sidebar .navsec { padding: 10px 16px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #7b90a6; }

/* main */
#main { flex: 1; padding: 18px 22px; min-width: 0; }
.view-title { font-size: 20px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.view-title .spacer { flex: 1; }

/* panels & cards */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 14px; }
.cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; min-width: 160px; flex: 1; }
.card .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.card .value { font-size: 22px; font-weight: 700; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th { background: var(--head); text-align: left; padding: 7px 9px; font-size: 12px; border-bottom: 2px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
td { padding: 6px 9px; border-bottom: 1px solid #eceff3; font-size: 13px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #eaf3fb; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); max-height: 65vh; overflow-y: auto; }
.neg { color: var(--red); }
.pos { color: var(--green); }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; width: 100%; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc7ea; border-color: var(--accent); }
input[type="checkbox"] { width: auto; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.formgrid .wide { grid-column: span 2; }
.formrow { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.formrow > div { min-width: 130px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
legend { font-size: 12px; font-weight: 600; color: var(--accent-dark); padding: 0 6px; }

/* buttons */
button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text); white-space: nowrap; }
button:hover { background: #f0f4f8; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-dark); }
button.success { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.danger { background: #fff; border-color: var(--red); color: var(--red); }
button.danger:hover { background: #fdf0ef; }
button.small { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.OPEN { background: #dcebf8; color: #0f4d85; }
.badge.POSTED { background: #ddf2e3; color: #1e7f3c; }
.badge.PAID { background: #ddf2e3; color: #1e7f3c; }
.badge.PARTIAL { background: #fdeeD3; background: #fdeed3; color: #92600a; }
.badge.RECEIVED { background: #ddf2e3; color: #1e7f3c; }
.badge.CANCELLED, .badge.REVERSED { background: #f3d9d7; color: #b3261e; }
.badge.QUOTE { background: #e9e2f7; color: #5b3fa8; }

/* modal */
#modal-overlay { position: fixed; inset: 0; background: rgba(15, 30, 45, 0.45); display: none; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow-y: auto; z-index: 50; }
#modal-overlay.open { display: flex; }
#modal { background: #fff; border-radius: 10px; width: 100%; max-width: 980px; padding: 18px 20px 22px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
#modal h2 { font-size: 17px; margin-bottom: 14px; }
#modal.narrow { max-width: 560px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .left { margin-right: auto; display: flex; gap: 8px; }

/* order editor lines */
#lines-table input { padding: 4px 6px; }
#lines-table td { padding: 3px 5px; }
.line-del { color: var(--red); cursor: pointer; font-weight: 700; padding: 0 6px; }

/* product thumbnails + hover preview */
img.thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); display: block; background: #fff; }
#img-preview { display: none; position: fixed; z-index: 90; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 12px 36px rgba(0,0,0,0.25); pointer-events: none; }
#img-preview img { max-width: 320px; max-height: 320px; display: block; border-radius: 6px; }

/* line selection + price history */
#lines-table tr.sel-line td { background: #fff3d6; }
.hist-box { background: #eef6ff; border: 1px solid #bcd7ef; border-radius: 6px; padding: 8px 10px; }
.hist-rows { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.hist-apply { background: #fff; }
.hist-apply:hover { background: #dcebf8; }

/* autocomplete */
.ac-wrap { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 0 0 6px 6px; max-height: 260px; overflow-y: auto; z-index: 20; box-shadow: 0 8px 20px rgba(0,0,0,0.12); }
.ac-item { padding: 7px 10px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 10px; }
.ac-item:hover, .ac-item.sel { background: #eaf3fb; }
.ac-item .m { color: var(--muted); font-size: 12px; }

/* login */
#login-overlay { position: fixed; inset: 0; background: #16283a; display: none; align-items: center; justify-content: center; z-index: 200; }
#login-overlay.open { display: flex; }
#login-card { background: #fff; border-radius: 12px; padding: 30px 34px; width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
#login-card h1 { font-size: 20px; margin-bottom: 4px; }
#login-card input { margin-top: 3px; }
#login-error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 17px; }

/* sidebar user footer */
#user-footer { padding: 12px 16px; border-top: 1px solid #24384d; font-size: 12.5px; color: #cfd8e3; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#user-footer .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#user-footer button { padding: 3px 10px; font-size: 12px; background: transparent; color: #8fa3b8; border-color: #3a5570; }
#user-footer button:hover { background: #1d3348; color: #fff; }

/* toast */
#toast { position: fixed; bottom: 20px; right: 20px; background: #16283a; color: #fff; padding: 10px 18px; border-radius: 8px; display: none; z-index: 99; max-width: 380px; }
#toast.err { background: var(--red); }

/* totals box */
.totals { margin-left: auto; width: 300px; }
.totals .trow { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13.5px; }
.totals .trow.grand { font-size: 17px; font-weight: 700; border-top: 2px solid var(--border); margin-top: 5px; padding-top: 7px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 12px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.searchbar input[type="text"], .searchbar input[type="date"] { width: auto; }
.searchbar select { width: auto; }

/* card receipts */
.cc-receipt { width: 300px; margin: 0 auto 10px; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
.cc-head { text-align: center; margin-bottom: 8px; }
.cc-title { text-align: center; font-weight: 700; border-top: 1px dashed #000; border-bottom: 1px dashed #000; padding: 3px 0; margin-bottom: 8px; }
.cc-row { display: flex; justify-content: space-between; padding: 1px 0; }
.cc-amt { display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; border-top: 1px dashed #000; margin-top: 8px; padding-top: 6px; }
.cc-agree { font-size: 10px; margin-top: 12px; }
.cc-sig { border-bottom: 1px solid #000; height: 34px; margin-top: 18px; font-size: 14px; }
.cc-sigline { font-size: 10px; text-align: center; margin-top: 2px; }
.cc-copy { text-align: center; margin-top: 12px; font-weight: 700; }
.cc-thanks { text-align: center; margin-top: 4px; }
.cc-cut { text-align: center; color: #666; margin: 14px 0; }

/* print */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; left: 0; top: 0; width: 100%; padding: 20px; background: #fff; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 4px 7px; font-size: 12px; }
  #print-area th { background: #eee !important; -webkit-print-color-adjust: exact; }
  #print-area .doc-head { display: flex; justify-content: space-between; margin-bottom: 14px; }
  #print-area h1 { font-size: 20px; margin-bottom: 4px; }
  #print-area h2 { font-size: 16px; text-align: center; margin: 10px 0; border: 1px solid #333; padding: 5px; }
}
