/* =====================================================================
   DJ Dairy Farm POS - application styles
   ===================================================================== */
:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0d9488;
  --brand-dark: #0f766e;
  --brand-ink: #ffffff;
  --accent: #f59e0b;
  --danger: #dc2626;
  --ok: #16a34a;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
  --mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- top bar ---------------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(180deg, #134e4a, #0f766e);
  color: #fff; padding: 0 18px; height: 56px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: #fff; color: var(--brand-dark); font-weight: 800;
  width: 36px; height: 36px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px; letter-spacing: .5px;
}
.brand-mark.brand-logo {
  /* uploaded logo is landscape + dark: white chip, wider box */
  width: 48px; height: 34px; background: #fff; padding: 3px;
  border-radius: 8px; font-size: 0;
}
.brand-mark.brand-logo img { width: 100%; height: 100%; display: block; object-fit: contain; }
.brand-text { font-weight: 700; font-size: 15px; line-height: 1.1; display: flex; flex-direction: column; }
.brand-text small { font-weight: 400; font-size: 10.5px; opacity: .8; letter-spacing: .3px; }

.mainnav { display: flex; gap: 2px; flex: 1; }
.mainnav a {
  color: #d1fae5; padding: 8px 13px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.mainnav a:hover { background: rgba(255, 255, 255, .12); text-decoration: none; color: #fff; }
.mainnav a.on { background: rgba(255, 255, 255, .18); color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.whoami { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.whoami strong { font-weight: 600; }
.whoami em { font-style: normal; }

/* ---------------- layout ---------------- */
.page { padding: 18px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.footbar {
  text-align: center; color: var(--muted); font-size: 12.5px; padding: 14px 0 22px;
}

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px;
}
.card h2 { font-size: 15.5px; margin: 0 0 12px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title-row h2 { margin: 0; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { background: #f8fafc; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; white-space: nowrap; }
table.data tbody tr:hover { background: #f8fafc; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .total-row td { font-weight: 800; background: #f0fdfa; border-top: 2px solid var(--brand); }
.empty { color: var(--muted); text-align: center; padding: 26px 0 !important; }

/* ---------------- forms ---------------- */
label.f { display: block; font-size: 12.5px; font-weight: 700; color: #475569; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14.5px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #99f6e4; border-color: var(--brand); }
input[disabled], select[disabled] { background: #f1f5f9; color: var(--muted); }
input.big { font-size: 20px; font-weight: 700; padding: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err-text { color: var(--danger); font-size: 12.5px; margin-top: 4px; font-weight: 600; }

/* ---------------- cashier access (Users screen) ---------------- */
.user-perms { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.user-perms:first-of-type { border-top: 0; padding-top: 4px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px 18px; margin: 10px 0 12px; }
.perm-grid label { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; cursor: pointer; color: #334155; }
.perm-grid input[type=checkbox] { width: auto; margin: 2px 0 0; accent-color: var(--brand); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 8px; padding: 10px 16px; font-size: 14.5px; font-weight: 700;
  cursor: pointer; font-family: inherit; background: #e2e8f0; color: var(--ink);
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-success { background: var(--ok); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-accent  { background: var(--accent); color: #422006; }
.btn-ghost   { background: rgba(255, 255, 255, .14); color: #fff; }
.btn-outline { background: #fff; border: 1px solid #cbd5e1; color: var(--ink); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16.5px; width: 100%; }
.btn-block { width: 100%; }

/* ---------------- badges & flash ---------------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-cashier { background: #dbeafe; color: #1e40af; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef9c3; color: #854d0e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0e7ff; color: #3730a3; }
.badge-muted { background: #f1f5f9; color: #475569; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 600; font-size: 14px; border: 1px solid; }
.flash-ok { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---------------- login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #134e4a, #0f766e 45%, #115e59); padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); padding: 30px; }
.login-card .brand-mark { width: 52px; height: 52px; font-size: 20px; margin-bottom: 12px; }
.login-card h1 { margin: 0 0 2px; font-size: 22px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }

/* ---------------- stat cards ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .v.money { color: var(--brand-dark); }
.stat .v.warn { color: var(--accent); }
.stat .v.danger { color: var(--danger); }

/* =====================================================================
   POS screen
   ===================================================================== */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .pos-layout { grid-template-columns: 1fr; } }

.pos-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.pos-toolbar .grow { flex: 1; min-width: 180px; }
.pos-search { font-size: 16px !important; padding: 11px 14px !important; }
.pos-cat { width: auto; min-width: 140px; }

.mode-toggle { display: inline-flex; background: #e2e8f0; border-radius: 10px; padding: 3px; gap: 3px; }
.mode-toggle button {
  border: 0; background: transparent; padding: 9px 16px; border-radius: 8px;
  font-weight: 800; font-size: 14px; cursor: pointer; font-family: inherit; color: #475569;
}
.mode-toggle button.on { background: var(--brand); color: #fff; box-shadow: 0 1px 4px rgba(13, 148, 136, .4); }
.mode-hint { font-size: 12.5px; color: var(--muted); }

.pos-table td { padding: 7px 8px; }
.pos-table .p-name { font-weight: 700; }
.pos-table .p-sku { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.pos-table .p-price { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pos-table .p-stock { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.pos-table .p-stock.low { color: var(--danger); font-weight: 700; }
.pos-table tr.active-row { background: #f0fdfa; }
.pos-table tr.over-stock { background: #fef2f2; }
.pos-table .unit-sel { width: 92px; padding: 7px 6px; font-size: 13.5px; }
.pos-table .qty-in { width: 118px; text-align: right; font-size: 16px; font-weight: 700; padding: 7px 9px; font-variant-numeric: tabular-nums; }
.pos-table .line-total { text-align: right; font-weight: 800; font-size: 15.5px; white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 96px; }
.pos-table .line-total.zero { color: #cbd5e1; }
.pos-table .mode-chip {
  font-size: 10.5px; font-weight: 800; padding: 2px 6px; border-radius: 5px;
  background: #e2e8f0; color: #475569; cursor: pointer; border: 0; font-family: inherit;
}
.pos-table .mode-chip.amt { background: #fef3c7; color: #92400e; }
.pos-table .mode-chip.qty { background: #dbeafe; color: #1e40af; }
.pos-table .derived { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.pos-table tr.row-warn .line-total { color: var(--danger); }

/* summary panel */
.pos-summary { position: sticky; top: 72px; }
.sum-lines { max-height: 250px; overflow-y: auto; margin: -4px -4px 10px; padding: 4px; }
.sum-line {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 8px 10px; border-radius: 8px; background: #f8fafc; margin-bottom: 6px; border: 1px solid var(--line);
}
.sum-line .n { font-weight: 700; font-size: 13.5px; }
.sum-line .t { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.sum-line .d { font-size: 12px; color: var(--muted); }
.sum-line .d.amt { color: #92400e; }
.sum-empty { color: var(--muted); font-size: 13.5px; text-align: center; padding: 18px 0; border: 1px dashed var(--line); border-radius: 8px; }

.totals { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.trow { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 14.5px; }
.trow .lbl { color: var(--muted); font-weight: 600; }
.trow .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.trow.grand { font-size: 21px; padding: 8px 0 2px; }
.trow.grand .lbl { color: var(--ink); font-weight: 800; }
.trow.grand .val { color: var(--brand-dark); font-weight: 800; }
.trow.change .val { color: var(--ok); }
.trow.due .val { color: var(--danger); }
.trow input { width: 130px; text-align: right; font-weight: 700; }

.paid-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.quick-cash button {
  border: 1px solid #cbd5e1; background: #fff; border-radius: 7px; padding: 5px 10px;
  font-size: 12.5px; font-weight: 700; cursor: pointer; font-family: inherit; color: #334155;
}
.quick-cash button:hover { background: #f0fdfa; border-color: var(--brand); }

.credit-note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; font-weight: 600; margin-top: 10px; }
.credit-note.over { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* success modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 100;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 430px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, .4); text-align: center;
}
.modal .tick { width: 58px; height: 58px; border-radius: 50%; background: #dcfce7; color: var(--ok); display: grid; place-items: center; font-size: 30px; margin: 0 auto 12px; font-weight: 800; }
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal .inv { font-family: var(--mono); font-size: 15px; color: var(--muted); margin-bottom: 14px; }
.modal .amt { font-size: 30px; font-weight: 800; color: var(--brand-dark); margin-bottom: 4px; }
.modal .meta { font-size: 13.5px; color: var(--muted); margin-bottom: 18px; line-height: 1.6; }
.modal .acts { display: flex; gap: 10px; justify-content: center; }

/* =====================================================================
   Thermal receipt (80 mm)
   ===================================================================== */
body.receipt-page { background: #fff; font-family: var(--mono); font-size: 12.5px; color: #000; }
.receipt { width: 292px; margin: 0 auto; padding: 10px 6px 24px; }
.receipt .rc-logo { text-align: center; margin: 0 0 6px; }
.receipt .rc-logo img { max-width: 130px; max-height: 64px; width: auto; height: auto; }
.receipt h1 { text-align: center; font-size: 17px; margin: 0 0 2px; letter-spacing: .5px; }
.receipt .rc-sub { text-align: center; font-size: 11px; margin-bottom: 2px; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 7px 0; }
.receipt .rc-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt .rc-item { margin-bottom: 5px; }
.receipt .rc-item .top { display: flex; justify-content: space-between; font-weight: 700; }
.receipt .rc-item .sub { display: flex; justify-content: space-between; font-size: 11px; }
.receipt .rc-tot { display: flex; justify-content: space-between; font-weight: 700; }
.receipt .rc-grand { font-size: 15px; font-weight: 800; }
.receipt .rc-thanks { text-align: center; margin-top: 10px; font-size: 11.5px; }
.receipt .num { font-variant-numeric: tabular-nums; }

@media print {
  .no-print, .topbar, .footbar, .page-head, .print-bar { display: none !important; }
  body.receipt-page { background: #fff; }
  .receipt { width: 76mm; margin: 0; padding: 0; }
  .receipt .rc-logo img { max-width: 24mm; max-height: 13mm; }
  @page { size: 80mm auto; margin: 3mm; }
}

/* print bar on receipt preview page */
.print-bar { display: flex; gap: 10px; justify-content: center; padding: 16px 0; }

/* ---------------- misc ---------------- */
.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters .f-group { display: flex; flex-direction: column; }
.filters input, .filters select { width: auto; min-width: 150px; }
.right { text-align: right; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.mt0 { margin-top: 0; }
.danger-text { color: var(--danger); font-weight: 700; }
.ok-text { color: var(--ok); font-weight: 700; }
.inline-form { display: inline; }
.pill-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* =====================================================================
   Mobile / small screens (admin + cashier on a phone)
   ===================================================================== */
.nav-toggle {
  display: none;
  background: transparent; border: 0; color: #fff; font-size: 22px;
  cursor: pointer; padding: 6px 10px; border-radius: 8px; line-height: 1;
}
.nav-toggle:hover { background: rgba(255, 255, 255, .12); }

@media (max-width: 768px) {
  .nav-toggle { display: grid; place-items: center; }
  .topbar { padding: 0 10px; gap: 8px; height: 52px; }
  .brand-text { font-size: 13.5px; }
  .brand-text small { display: none; }
  .brand-mark.brand-logo { width: 40px; height: 28px; }
  .whoami strong { display: none; }          /* keep role badge + logout visible */

  .mainnav {
    display: none;
    position: fixed; top: 52px; left: 0; right: 0;
    background: #0f766e; flex-direction: column; padding: 8px; gap: 2px;
    z-index: 60; box-shadow: 0 10px 24px rgba(0, 0, 0, .28);
  }
  .mainnav.open { display: flex; }
  .mainnav a { padding: 13px 14px; font-size: 15px; }

  .page { padding: 10px; }

  /* stats: two per row on a phone */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .v { font-size: 18px; }

  /* filters + forms stack full-width with big touch targets */
  .filters { flex-direction: column; align-items: stretch; }
  .filters .f-group { width: 100%; }
  .filters input, .filters select, .filters .btn, .filters a.btn { width: 100%; min-height: 42px; }
  .form-grid { grid-template-columns: 1fr; }
  .page input, .page select, .page textarea { min-height: 42px; font-size: 16px; }
  .page .btn { min-height: 42px; }
  .page .btn-sm { min-height: 36px; font-size: 13px; }

  /* wide data tables scroll horizontally instead of crushing columns */
  .table-wrap table.data { min-width: 560px; }

  /* POS: summary flows below the product list; bill header sticks under the topbar */
  .pos-summary { position: sticky; top: 60px; }
  .pos-layout { gap: 10px; }

  /* POS table: horizontal scroll with sticky product column on phones */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .pos-table th:first-child,
  .pos-table td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--panel);
    box-shadow: 2px 0 4px rgba(15, 23, 42, .06);
  }
  .pos-table tr.active-row td:first-child { background: #f0fdfa; }
  .pos-table tr.over-stock td:first-child { background: #fef2f2; }
  .qty-in { min-height: 40px; }
  .unit-sel { min-height: 40px; }
  .mode-toggle button { min-height: 38px; padding: 8px 14px; }
  .pos-summary { position: static; } /* let the bill flow naturally on phones */
}

@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .k { font-size: 11px; }
  .stat .v { font-size: 16.5px; }
  .page-head h1 { font-size: 18px; }
}
