:root {
  --bg: #f7efe7;
  --card: #fffaf5;
  --ink: #2c1e16;
  --muted: #7d6757;
  --coffee: #6f3f25;
  --coffee-dark: #3f2518;
  --gold: #d49a48;
  --green: #168047;
  --red: #c64040;
  --line: #ead8c8;
  --shadow: 0 18px 45px rgba(70, 39, 24, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff6df 0, transparent 30%), var(--bg);
  color: var(--ink);
}

.app-shell { max-width: 1220px; margin: 0 auto; padding: 28px 18px 56px; }
.hero {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 340px);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}
.hero > div:first-child, .card, .summary-card {
  background: rgba(255, 250, 245, .92);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.hero > div:first-child { padding: 34px; }
.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 12px;
  color: var(--coffee);
  font-weight: 800;
}
h1, h2 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(34px, 5vw, 58px); }
h2 { font-size: 24px; }
.subtitle { color: var(--muted); max-width: 720px; font-size: 17px; line-height: 1.55; }
.hero-card {
  border-radius: 24px;
  padding: 28px;
  color: white;
  background: linear-gradient(145deg, var(--coffee-dark), var(--coffee));
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 210px;
  box-shadow: var(--shadow);
}
.hero-label { color: #f6d7a4; font-weight: 700; }
.hero-card strong { font-size: 38px; margin-top: 12px; }
.hero-card small { color: #f9e8ce; margin-top: 8px; }

.toolbar { padding: 16px; display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
label { display: grid; gap: 6px; font-weight: 700; color: var(--muted); font-size: 13px; }
select, input {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--ink);
  padding: 12px 13px;
  font-size: 15px;
  outline: none;
}
select:focus, input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,154,72,.18); }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  background: #efe0d2;
  color: var(--coffee-dark);
  font-weight: 800;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(.98); }
.btn.primary { background: var(--coffee); color: white; }
.btn.danger { background: #ffe0dd; color: var(--red); }
.file-btn { display: inline-flex; align-items: center; justify-content: center; color: var(--coffee-dark); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(145px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.summary-card { padding: 18px; }
.summary-card span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-card strong { display: block; margin-top: 8px; font-size: 22px; }
.summary-card.net.profit strong, .profit { color: var(--green); }
.summary-card.net.loss strong, .loss { color: var(--red); }

.quick-input-card, .table-card { padding: 18px; }
.quick-input-card { margin-bottom: 18px; }
.section-head { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 14px; }
.autosave, .quick-net { margin: 0; color: var(--green); font-weight: 800; }
.quick-net.loss { color: var(--red); }
.quick-form {
  display: grid;
  grid-template-columns: 150px minmax(190px, 1fr) minmax(220px, 1.2fr) auto auto;
  gap: 12px;
  align-items: end;
}
.quick-form input, .quick-form select { width: 100%; }
.purchase-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffdf9;
}
.purchase-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.purchase-head h3 { margin: 0; font-size: 19px; }
.purchase-head strong { color: var(--coffee); font-size: 18px; white-space: nowrap; }
.purchase-table-wrap { overflow-x: auto; margin-bottom: 12px; }
.purchase-table { min-width: 560px; table-layout: fixed; }
.purchase-table th:nth-child(1) { width: 210px; }
.purchase-table th:nth-child(2) { width: 82px; }
.purchase-table th:nth-child(3) { width: 120px; }
.purchase-table th:nth-child(4) { width: 120px; }
.purchase-table th:nth-child(5) { width: 56px; }
.purchase-table input { width: 100%; border-radius: 10px; padding: 9px 8px; }
.purchase-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.purchase-actions .btn.primary { flex: 1; min-width: 230px; }
.purchase-total-cell { font-weight: 900; white-space: nowrap; }
.icon-btn {
  border: 0;
  background: #ffe0dd;
  color: var(--red);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  line-height: 1;
}
.form-help { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; border-radius: 18px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 1040px; background: white; }
th, td { padding: 12px; border-bottom: 1px solid #f0dfd1; text-align: left; }
th { background: #f4e5d5; color: var(--coffee-dark); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
tfoot th { background: #f0d9c0; font-size: 14px; }
.date-cell { font-weight: 800; white-space: nowrap; }
.money-input, .note-input { width: 100%; border-radius: 10px; padding: 10px 11px; }
.row-actions { white-space: nowrap; }
.mini-btn {
  border: 0;
  border-radius: 9px;
  padding: 8px 9px;
  margin-right: 5px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  background: #efe0d2;
  color: var(--coffee-dark);
}
.mini-btn.delete-day { background: #ffe0dd; color: var(--red); }
.net-cell { font-weight: 900; white-space: nowrap; }
tr.has-profit .net-cell { color: var(--green); }
tr.has-loss .net-cell { color: var(--red); }

@media (max-width: 1100px) {
  .quick-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .quick-note-label { grid-column: 1 / -1; }
  .purchase-head { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 920px) {
  .hero { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .app-shell { padding: 16px 10px 42px; overflow-x: hidden; }
  .hero > div:first-child, .hero-card, .card, .summary-card { border-radius: 18px; }
  .hero > div:first-child { padding: 22px; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .toolbar .btn, .toolbar label { width: 100%; min-width: 0; }
  .quick-form { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { padding: 14px; min-width: 0; }
  .summary-card strong { font-size: 18px; overflow-wrap: anywhere; }
  .purchase-box { padding: 10px; margin-left: -4px; margin-right: -4px; overflow: hidden; }
  .purchase-table-wrap { overflow-x: hidden; }
  .purchase-table,
  .purchase-table tbody,
  .purchase-table tr,
  .purchase-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .purchase-table { table-layout: auto; }
  .purchase-table thead { display: none; }
  .purchase-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffaf5;
  }
  .purchase-table td {
    border: 0;
    padding: 0;
    font-size: 12px;
    min-width: 0;
  }
  .purchase-table td::before {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  .purchase-table td:nth-child(1) { grid-column: 1 / -1; }
  .purchase-table td:nth-child(1)::before { content: 'Nama Barang'; }
  .purchase-table td:nth-child(2)::before { content: 'Qty'; }
  .purchase-table td:nth-child(3)::before { content: 'U/P'; }
  .purchase-table td:nth-child(4)::before { content: 'Jumlah'; }
  .purchase-table td:nth-child(5)::before { content: 'Aksi'; }
  .purchase-table td:nth-child(5) { display: flex; align-items: end; }
  .purchase-table input {
    max-width: 100%;
    padding: 10px 8px;
    border-radius: 9px;
    font-size: 14px;
  }
  .purchase-total-cell {
    min-height: 40px;
    display: flex !important;
    flex-direction: column;
    justify-content: end;
    font-size: 14px;
    overflow-wrap: anywhere;
  }
  .purchase-actions { display: grid; grid-template-columns: 1fr; gap: 9px; }
  .purchase-actions .btn, .purchase-actions .btn.primary { width: 100%; min-width: 0; }
  .icon-btn { width: 100%; padding: 10px 8px; border-radius: 9px; }
}
@media print {
  body { background: white; }
  .toolbar, .autosave { display: none; }
  .app-shell { max-width: none; padding: 0; }
  .hero, .summary-grid { break-inside: avoid; }
  .card, .summary-card, .hero > div:first-child { box-shadow: none; }
}

@media (max-width: 420px) {
  .summary-grid { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; }
  .purchase-table tr { grid-template-columns: 1fr; }
  .purchase-table td:nth-child(1),
  .purchase-table td:nth-child(2),
  .purchase-table td:nth-child(3),
  .purchase-table td:nth-child(4),
  .purchase-table td:nth-child(5) { grid-column: 1 / -1; }
}

.receipt-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
}
.manual-input-box,
.ocr-box {
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: #fffaf5;
  padding: 14px;
}
.receipt-tool-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.receipt-tool-head h3 { margin: 0; font-size: 18px; }
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--ink);
  padding: 12px 13px;
  font-size: 14px;
  line-height: 1.45;
  outline: none;
  resize: vertical;
  min-height: 130px;
}
textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,154,72,.18); }
.ocr-preview-wrap {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
#receiptPreview {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
}
.ocr-status {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 920px) {
  .receipt-tools { grid-template-columns: 1fr; }
  .receipt-tool-head { align-items: flex-start; flex-direction: column; }
  .receipt-tool-head .btn,
  .receipt-tool-head .file-btn { width: 100%; }
}
@media (max-width: 520px) {
  .ocr-preview-wrap { grid-template-columns: 1fr; }
  #receiptPreview { width: 100%; height: 180px; }
}

.camera-actions-top,
.camera-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.camera-panel {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffdf9;
}
#cameraVideo {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 14px;
  background: #22170f;
  display: block;
  margin-bottom: 10px;
}
@media (max-width: 920px) {
  .camera-actions-top,
  .camera-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .camera-actions-top .btn,
  .camera-actions .btn { width: 100%; }
}


.camera-btn,
.file-btn {
  gap: 7px;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


body.modal-open { overflow: hidden; }
.purchase-modal[hidden] { display: none; }
.purchase-modal { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 18px; }
.purchase-modal-backdrop { position: absolute; inset: 0; background: rgba(44, 30, 22, .48); backdrop-filter: blur(3px); }
.purchase-modal-card {
  position: relative;
  width: min(980px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 28px 80px rgba(44, 30, 22, .28);
  padding: 20px;
}
.purchase-modal-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.purchase-modal-summary { margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.modal-close { border: 0; background: #ffe0dd; color: var(--red); width: 40px; height: 40px; border-radius: 14px; font-size: 28px; line-height: 1; cursor: pointer; font-weight: 900; }
.daily-purchase-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: white; }
.daily-purchase-table { min-width: 760px; }
.daily-purchase-table th:nth-child(1), .daily-purchase-table td:nth-child(1) { width: 56px; text-align: center; }
.daily-purchase-table th:nth-child(2), .daily-purchase-table td:nth-child(2) { min-width: 240px; }
.empty-purchase-detail { border: 1px dashed var(--line); background: #fffdf9; border-radius: 16px; padding: 18px; color: var(--muted); }
.empty-purchase-detail strong { color: var(--coffee-dark); }
.mini-btn.view-purchases { background: #e3f3e9; color: var(--green); }
@media (max-width: 820px) {
  .purchase-modal { padding: 10px; align-items: end; }
  .purchase-modal-card { max-height: 92vh; border-radius: 20px 20px 0 0; padding: 16px; }
  .purchase-modal-head { align-items: flex-start; }
  .daily-purchase-table { min-width: 680px; }
  .modal-close { flex: 0 0 auto; }
}
.login-screen[hidden], .app-shell[hidden] { display: none !important; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at top left, #fff6df 0, transparent 35%), var(--bg); }
.login-card { width: min(460px, 100%); background: rgba(255,250,245,.96); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); padding: 28px; }
.login-card h1 { font-size: clamp(30px, 7vw, 44px); }
.login-form { display: grid; gap: 14px; margin-top: 18px; }
.login-form input { width: 100%; }
.login-error { min-height: 20px; color: var(--red); font-weight: 800; margin: 0; }
.session-pill { display: inline-flex; gap: 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--line); background: #fffaf5; border-radius: 14px; color: var(--coffee-dark); font-weight: 900; }
body[data-role="operator"] .toolbar #exportBtn,
body[data-role="operator"] .toolbar #resetBtn,
body[data-role="operator"] .toolbar .file-btn,
body[data-role="operator"] .edit-day,
body[data-role="operator"] .delete-day { display: none !important; }
body[data-role="operator"] .row-actions::after { content: 'Input via form harian'; color: var(--muted); font-size: 12px; font-weight: 800; }
@media (max-width: 820px) { .session-pill { grid-column: 1 / -1; justify-content: space-between; } }

.inline-purchase-detail { margin-top: 18px; padding: 18px; }
body[data-role="operator"] .view-purchases { display: inline-block !important; }
