:root {
  --paper: #F7F3EA;
  --ink: #22303D;
  --ink-soft: #66747F;
  --line: #E1D8C6;
  --card: #FFFFFF;
  --carbon: #E39AA5;
  --stamp: #B94636;
  --stamp-dark: #7A2E22;
  --gold: #C89A46;
  --ok: #4C7A4E;
  --danger: #B94636;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #EAE3D4;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  padding: 16px 18px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 5;
}

.brand {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.5px;
}
.brand span { color: var(--stamp); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.screen { flex: 1; padding-bottom: 90px; display: none; }
.screen.active { display: block; }

.section-label {
  font-family: 'Space Mono', monospace; font-size: 11px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--ink-soft); padding: 0 18px; margin: 14px 0 8px;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 18px 4px; }
.chip {
  flex: 0 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 7px 13px; font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px;
  white-space: nowrap; cursor: pointer;
}
.chip.selected { border-color: var(--stamp); color: var(--stamp-dark); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip .count { color: var(--ink-soft); font-family: 'Space Mono', monospace; font-size: 11px; }

.doc-list { padding: 4px 18px 12px; display: flex; flex-direction: column; gap: 16px; }
.empty-state {
  margin: 40px 18px; text-align: center; color: var(--ink-soft); font-size: 14px;
}
.doc-card-wrap { position: relative; cursor: pointer; }
.doc-duplicate {
  position: absolute; top: 6px; left: 6px; right: -6px; bottom: -6px;
  background: var(--carbon); border-radius: 10px; opacity: 0.55;
}
.doc-card {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; gap: 12px; align-items: center;
}
.doc-thumb {
  width: 42px; height: 52px; border-radius: 4px; background: #fff; border: 1px solid var(--line);
  flex: 0 0 auto; object-fit: cover;
}
.doc-meta { flex: 1; min-width: 0; }
.doc-name { font-weight: 500; font-size: 14px; margin: 0 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-size: 12px; color: var(--ink-soft); margin: 0; }
.doc-tag { font-family: 'Space Mono', monospace; font-size: 10px; padding: 3px 7px; border-radius: 5px; font-weight: 700; white-space: nowrap; }

.fab {
  position: fixed; right: calc(50% - 240px + 18px); bottom: 92px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--stamp); border: 3px solid var(--paper); display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 6;
}
@media (max-width: 480px) { .fab { right: 18px; } }

.tabbar {
  position: sticky; bottom: 0; left: 0; right: 0; height: 64px; background: var(--card);
  border-top: 1px solid var(--line); display: flex; z-index: 5;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 10px; color: var(--ink-soft); font-weight: 500; cursor: pointer; background: none; border: none; font-family: inherit;
}
.tab.active { color: var(--stamp); }
.tab svg { width: 20px; height: 20px; }

.scan-view { padding: 16px 18px; }
.viewfinder {
  position: relative; width: 100%; aspect-ratio: 3/4; background: #12181D; border-radius: 14px; overflow: hidden;
}
.viewfinder video, .viewfinder canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.vf-badge {
  position: absolute; top: 12px; left: 12px; background: rgba(76,122,78,0.9); color: #fff;
  font-family: 'Space Mono', monospace; font-size: 10px; padding: 4px 8px; border-radius: 5px;
}
.vf-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; text-align: center; padding: 24px; background: rgba(18,24,29,0.6);
}
.scan-controls { display: flex; align-items: center; justify-content: center; gap: 34px; margin-top: 20px; }
.shutter {
  width: 66px; height: 66px; border-radius: 50%; background: #fff; border: 4px solid var(--stamp); cursor: pointer;
}
.shutter:active { transform: scale(0.95); }
.side-btn {
  width: 40px; height: 40px; border-radius: 50%; background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.thumbstrip { display: flex; gap: 8px; padding: 16px 0; flex-wrap: wrap; }
.thumb { width: 48px; height: 60px; border-radius: 5px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.field-label { font-size: 12px; color: var(--ink-soft); margin: 16px 0 6px; }
.text-input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: var(--card); color: var(--ink); font-family: inherit;
}
.btn {
  width: 100%; padding: 12px; border-radius: 8px; border: none; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--stamp); color: #fff; }
.btn-secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn:active { transform: scale(0.98); }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.format-toggle { display: flex; gap: 8px; margin-top: 8px; }
.format-option {
  flex: 1; padding: 10px; text-align: center; border-radius: 8px; border: 1px solid var(--line);
  font-size: 13px; cursor: pointer; background: var(--card);
}
.format-option.selected { border-color: var(--stamp); background: #F3DDDA; color: var(--stamp-dark); font-weight: 600; }

.folder-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 6px 18px 12px; }
.folder {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; position: relative;
  padding-top: 24px; cursor: pointer;
}
.folder-tab { position: absolute; top: -8px; left: 14px; width: 44px; height: 16px; border-radius: 4px 4px 0 0; }
.folder-name { font-weight: 600; font-size: 13px; margin: 0 0 4px; }
.folder-count { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--ink-soft); }
.add-folder {
  border: 1.5px dashed var(--line); display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: 13px; font-weight: 500; min-height: 76px; background: none;
}

.searchbar {
  margin: 4px 18px 0; display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.searchbar input { border: none; background: transparent; outline: none; font-size: 13px; flex: 1; font-family: inherit; color: var(--ink); }
.filter-row { display: flex; gap: 8px; padding: 12px 18px 4px; flex-wrap: wrap; }
.filter-chip {
  font-size: 11px; font-family: 'Space Mono', monospace; border: 1px solid var(--line); background: var(--card);
  border-radius: 16px; padding: 5px 10px; color: var(--ink-soft); cursor: pointer;
}
.filter-chip.on { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.result-snip mark { background: #F3DDA0; color: var(--ink); border-radius: 2px; padding: 0 2px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18,24,29,0.5); display: none;
  align-items: flex-end; justify-content: center; z-index: 20;
}
.modal-backdrop.open { display: flex; }
.modal-sheet {
  width: 100%; max-width: 480px; background: var(--paper); border-radius: 16px 16px 0 0; padding: 20px 18px 28px;
  max-height: 80vh; overflow-y: auto;
}
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: #EAE3D4;
}
.auth-card {
  width: 100%; max-width: 360px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px;
}
.auth-card a { color: var(--stamp); text-decoration: none; font-weight: 500; }

.corner-overlay { align-items: stretch; }
.corner-sheet {
  width: 100%; max-width: 480px; height: 100vh; background: var(--paper);
  border-radius: 0; padding: 16px 18px; display: flex; flex-direction: column;
  box-sizing: border-box; margin: 0 auto;
}
.corner-host {
  flex: 1; position: relative; background: #12181D; border-radius: 10px;
  margin: 4px 0 12px; overflow: hidden; min-height: 0;
}
.corner-host :is(canvas, img) { max-width: 100%; max-height: 100%; }

.account-row {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.account-row:last-child { border-bottom: none; }
.user-row {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.user-row:last-child { border-bottom: none; }
.role-badge {
  font-family: 'Space Mono', monospace; font-size: 10px; padding: 2px 7px; border-radius: 4px;
  text-transform: uppercase; font-weight: 700;
}
.role-badge.admin { background: #F3DDDA; color: var(--stamp-dark); }
.role-badge.user { background: #E3EEE3; color: #2F4E30; }

.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 20px; font-size: 13px; z-index: 30; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; }

/* --- Responsif: tablet & desktop ---
   Reka bentuk di atas dibina "mobile-first". Pada skrin lebih luas, guna
   ruang terpakai dengan baik — kad dokumen & folder susun jadi berbilang
   lajur, bukan sekadar kekal dalam satu lajur sempit di tengah skrin kosong.
   Skrin kamera (.scan-view) sengaja dikekalkan pada saiz sederhana supaya
   paparan kamera tak jadi besar/herot tak menentu. */
@media (min-width: 720px) {
  .app-shell { max-width: 760px; }
  .topbar, .section-label, .chips, .filter-row, .doc-list, .folder-grid {
    padding-left: 24px; padding-right: 24px;
  }
  .searchbar { margin-left: 24px; margin-right: 24px; }
  .doc-list { display: grid; grid-template-columns: repeat(2, 1fr); }
  .folder-grid { grid-template-columns: repeat(3, 1fr); }
  .fab { right: calc(50% - 380px + 24px); bottom: 32px; }
  .scan-view { max-width: 480px; margin: 0 auto; }
}

@media (min-width: 1080px) {
  .app-shell { max-width: 1120px; }
  .brand { font-size: 23px; }
  .topbar, .section-label, .chips, .filter-row, .doc-list, .folder-grid {
    padding-left: 32px; padding-right: 32px;
  }
  .searchbar { margin-left: 32px; margin-right: 32px; }
  .doc-list { grid-template-columns: repeat(3, 1fr); }
  .folder-grid { grid-template-columns: repeat(4, 1fr); }
  .fab { right: calc(50% - 560px + 32px); width: 60px; height: 60px; }
}
