/* ITMind POS — plain CSS, no build step, no external fonts or CDNs. */

:root {
  --brand: #0f6b4c;
  --brand-dark: #0b5038;
  --brand-light: #e7f5ee;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1b2420;
  --muted: #5c6b64;
  --border: #d9e2dd;
  --danger: #b3261e;
  --danger-bg: #fbeae8;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --focus: #1a73e8;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(16, 40, 30, 0.08);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11140f;
    --surface: #1a1f19;
    --text: #e9efea;
    --muted: #a7b3ac;
    --border: #2b332c;
    --brand-light: #163427;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }

a { color: var(--brand-dark); }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--brand); color: #fff; padding: 0.5em 1em; z-index: 1000;
}
.skip-link:focus { left: 0.5em; top: 0.5em; border-radius: var(--radius); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- buttons & forms */

.btn {
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.55em 1em; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; min-height: 2.6em;
}
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-pay { font-size: 1.1em; padding: 0.7em 1.4em; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.1em; padding: 0.2em 0.5em; color: var(--danger); }

input[type="text"], input[type="search"], input[type="password"], input[type="number"],
input[type="date"], input[type="url"], input[type="tel"], select {
  padding: 0.5em 0.6em; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 2.5em;
}
input[type="checkbox"] { width: 1.2em; height: 1.2em; }

.field { display: flex; flex-direction: column; gap: 0.3em; margin-bottom: 0.9em; }
.field.inline { flex-direction: row; align-items: center; gap: 0.5em; }
.field span { font-size: 0.9em; color: var(--muted); }
.checkbox-label { display: flex; align-items: center; gap: 0.5em; margin-bottom: 0.9em; }

.row { display: flex; align-items: center; }
.row.gap { gap: 0.6em; }
.row.end { justify-content: flex-end; }

.error-banner {
  background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger);
  border-radius: var(--radius); padding: 0.7em 1em;
}

/* ---------------------------------------------------------------- toasts */

.toast-host { position: fixed; bottom: 1em; right: 1em; display: flex; flex-direction: column; gap: 0.5em; z-index: 2000; max-width: 24em; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0.8em 1em; opacity: 0; transform: translateY(8px); transition: 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--brand); }
.toast-error { border-color: var(--danger); color: var(--danger); }

/* ---------------------------------------------------------------- modal */

dialog.app-modal { border: none; border-radius: var(--radius); padding: 1.4em; box-shadow: var(--shadow); max-width: min(90vw, 640px); width: 100%; }
dialog.app-modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.item-form, .settings-form, .ledger-modal, .payment-modal, .picker, .confirm-dialog { display: flex; flex-direction: column; gap: 0.4em; }
.picker-list { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.picker-item { padding: 0.6em 0.8em; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-item:hover, .picker-item:focus { background: var(--brand-light); }
.picker-new { font-weight: 600; color: var(--brand-dark); }

/* ---------------------------------------------------------------- top bar / nav */

.topbar {
  display: flex; align-items: center; gap: 1em; padding: 0.6em 1em;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--brand-dark); }
.main-nav { display: flex; gap: 0.3em; flex-wrap: wrap; flex: 1; }
.nav-link { padding: 0.5em 0.8em; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.nav-link:hover { background: var(--brand-light); }
.nav-link.active { background: var(--brand); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 0.8em; }
.user-chip { color: var(--muted); font-size: 0.9em; }
.sync-badge { font-size: 0.85em; padding: 0.3em 0.6em; border-radius: 999px; border: 1px solid var(--border); }
.sync-badge.online { color: var(--brand-dark); border-color: var(--brand); }
.sync-badge.offline { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; }
.dot.online { background: var(--brand); }
.dot.offline { background: var(--warn); }

main#screen-root { padding: 1em; max-width: 1400px; margin: 0 auto; }
.loading { padding: 2em; text-align: center; }

/* ---------------------------------------------------------------- login & settings */

.login-screen { display: flex; justify-content: center; align-items: center; min-height: 90vh; padding: 1em; }
.login-form {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2em; max-width: 24em; width: 100%; display: flex; flex-direction: column; gap: 0.6em;
}
.settings-screen { display: flex; flex-direction: column; gap: 1.2em; max-width: 46em; margin: 0 auto; }
.settings-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2em 1.4em; }
.danger-zone { border-color: var(--danger); }
.sync-status { display: flex; flex-wrap: wrap; gap: 0.4em; align-items: center; margin-bottom: 0.8em; }

/* ---------------------------------------------------------------- data tables */

.toolbar { display: flex; gap: 0.6em; flex-wrap: wrap; align-items: center; margin-bottom: 0.8em; }
.items-screen, .reports-screen { display: flex; flex-direction: column; gap: 0.6em; }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 0.5em 0.7em; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { background: var(--brand-light); font-weight: 600; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.empty-row { text-align: center; color: var(--muted); padding: 1.5em; }
.num.bad { color: var(--danger); font-weight: 600; }
.num.warn { color: var(--warn); font-weight: 600; }
.tag { display: inline-block; font-size: 0.75em; background: var(--brand-light); color: var(--brand-dark); border-radius: 999px; padding: 0.1em 0.6em; }

/* ---------------------------------------------------------------- sell screen */

.sell-screen { display: grid; grid-template-columns: 1fr 22em; gap: 1em; align-items: start; }
.sell-main { display: flex; flex-direction: column; gap: 0.8em; }
.sell-side { display: flex; flex-direction: column; gap: 0.8em; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1em; position: sticky; top: 1em; }
.search-wrap { position: relative; }
.search-wrap input { width: 100%; font-size: 1.1em; padding: 0.7em; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 50; max-height: 60vh; overflow: auto;
}
.search-item { display: flex; justify-content: space-between; gap: 0.6em; padding: 0.6em 0.8em; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-item:hover, .search-item:focus { background: var(--brand-light); }
.si-name { flex: 1; font-weight: 500; }
.si-meta { color: var(--muted); font-size: 0.85em; }
.si-price { font-variant-numeric: tabular-nums; font-weight: 600; }

.cart-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); }
.cart-table th, .cart-table td { padding: 0.4em 0.5em; border-bottom: 1px solid var(--border); text-align: left; }
.cart-table th { background: var(--brand-light); }
.col-name { min-width: 10em; }
.qty-input, .disc-input { width: 4.5em; }
.price-input { width: 6em; }

.customer-row { display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; }
.customer-name { font-weight: 600; flex: 1; }
.customer-meta { color: var(--muted); font-size: 0.85em; margin: 0.3em 0 0.6em; }

.totals-grid { display: flex; flex-direction: column; gap: 0.3em; }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6em; }
.totals-row.net-row { font-size: 1.2em; font-weight: 700; border-top: 1px solid var(--border); padding-top: 0.4em; margin-top: 0.2em; }
.totals-input { width: 6em; text-align: right; }

.held-list { display: flex; flex-direction: column; gap: 0.4em; }
.held-row { display: flex; justify-content: space-between; align-items: center; gap: 0.4em; font-size: 0.9em; }

.pay-lines { display: flex; flex-direction: column; gap: 0.5em; }
.pay-line { display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; }
.pay-summary { display: flex; gap: 1em; font-weight: 600; margin: 0.6em 0; flex-wrap: wrap; }

/* ---------------------------------------------------------------- reports */

.dashboard-cards { display: flex; gap: 0.8em; flex-wrap: wrap; }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8em 1.2em; min-width: 9em; }
.dash-card.warn { border-color: var(--warn); background: var(--warn-bg); }
.dash-value { font-size: 1.4em; font-weight: 700; }
.dash-label { color: var(--muted); font-size: 0.85em; }
.reports-layout { display: grid; grid-template-columns: 14em 1fr; gap: 1em; align-items: start; }
.report-groups { display: flex; flex-direction: column; gap: 0.1em; }
.report-groups h4 { margin: 0.8em 0 0.2em; color: var(--muted); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.04em; }
.report-link { text-align: left; background: none; border: none; padding: 0.5em 0.6em; border-radius: var(--radius); cursor: pointer; }
.report-link:hover { background: var(--brand-light); }
.report-link.active { background: var(--brand); color: #fff; }
.report-result { min-width: 0; overflow: auto; }

/* ---------------------------------------------------------------- print receipt */

.print-only { display: none; }
@media print {
  .skip-link, #app { display: none !important; }
  .print-only { display: block !important; }
  .receipt { width: 72mm; margin: 0 auto; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
  .r-center { text-align: center; }
  .r-company { font-weight: 700; font-size: 1.2em; }
  .r-rule { border-top: 1px dashed #000; margin: 4px 0; }
  .r-row { display: flex; justify-content: space-between; gap: 0.5em; }
  .r-net { font-weight: 700; font-size: 1.1em; }
  table.r-lines, table.r-pay { width: 100%; border-collapse: collapse; }
  .r-item-name { padding-top: 3px; }
  .r-qty, .r-price, .r-disc, .r-amount { text-align: right; }
  .r-qty { text-align: left; }
  .r-offline { font-weight: 700; margin-top: 4px; }
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 880px) {
  .sell-screen { grid-template-columns: 1fr; }
  .sell-side { position: static; }
  .reports-layout { grid-template-columns: 1fr; }
  main#screen-root { padding: 0.6em; }
  .topbar { gap: 0.5em; }
}

@media (max-width: 520px) {
  .data-table th, .data-table td { padding: 0.4em; font-size: 0.9em; }
  .login-form { padding: 1.2em; }
}
