/* ============================================================
   FILE DEPOT — token system
   Ý tưởng: sổ kho / phiếu vận đơn (cargo manifest), không dùng
   bảng màu mặc định (kem+terracotta / đen+neon).
   ============================================================ */
:root {
  --ink-900: #0F1626;
  --ink-800: #182238;
  --ink-700: #24304C;
  --ink-600: #384769;

  --paper: #F4EFE3;
  --paper-dim: #E9E1CE;

  --amber: #F0A93A;
  --amber-dark: #C97F0E;

  --rust: #B8452F;
  --rust-dark: #8F3222;

  --text-on-ink: #ECE7D8;
  --text-on-ink-dim: #9AA5BF;
  --text-on-paper: #1B2437;
  --text-on-paper-dim: #5B6478;

  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: 'Inter', sans-serif;

  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--ink-900);
  color: var(--text-on-ink);
  font-family: var(--font-body);
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

button, input {
  font-family: inherit;
}

/* ---------- background texture: faint grid, like a ledger ---------- */
body {
  background-image:
    linear-gradient(rgba(255,255,255,0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.028) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ============================================================
   GATE (login)
   ============================================================ */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pass-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  color: var(--text-on-paper);
  border-radius: var(--radius);
  padding: 40px 32px 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}

.pass-perf {
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 20px;
  background-image: radial-gradient(circle, var(--ink-900) 5px, transparent 5.5px);
  background-size: 22px 20px;
  background-position: 11px center;
}

.pass-eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-on-paper-dim);
}

.pass-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.02em;
}

.pass-sub {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--text-on-paper-dim);
}

.pass-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-on-paper-dim);
}

.field input {
  border: 1.5px solid var(--ink-900);
  background: #fff;
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text-on-paper);
}

.pass-error {
  margin: -6px 0 0;
  font-size: 13px;
  color: var(--rust-dark);
  font-weight: 600;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-stamp {
  width: 100%;
  background: var(--amber);
  color: #241703;
  border: 2px solid var(--ink-900);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-family: var(--font-display);
}
.btn-stamp:hover { background: var(--amber-dark); }

.btn-primary {
  background: var(--amber);
  color: #241703;
}
.btn-primary:hover { background: var(--amber-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text-on-ink-dim);
  border: 1px solid var(--ink-600);
}
.btn-ghost:hover { color: var(--text-on-ink); border-color: var(--text-on-ink-dim); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--ink-600);
  color: var(--text-on-ink-dim);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-on-ink); border-color: var(--amber); }
.icon-btn.danger:hover { color: var(--rust); border-color: var(--rust); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
  margin-bottom: 28px;
  border-bottom: 1px dashed var(--ink-600);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  background: var(--amber);
  color: #241703;
  border-radius: var(--radius);
  padding: 6px 9px;
  letter-spacing: 0.02em;
}

.brand-text { display: flex; flex-direction: column; }

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.03em;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-on-ink-dim);
}

/* ---------- intake / dropzone ---------- */
.intake {
  border: 2px dashed var(--ink-600);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  margin-bottom: 20px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.intake.drag-over {
  border-color: var(--amber);
  background: rgba(240, 169, 58, 0.06);
}

.intake-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.intake-label {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
}

.intake-or {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-on-ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---------- upload tray (progress tickets) ---------- */
.upload-tray {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.upload-ticket {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.upload-ticket-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--text-on-ink-dim);
}

.upload-ticket-row span:first-child { color: var(--text-on-ink); }

.progress-track {
  height: 5px;
  background: var(--ink-700);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--amber);
  width: 0%;
  transition: width 0.15s ease;
}

.upload-ticket.error .progress-fill { background: var(--rust); }
.upload-ticket.error .upload-ticket-row span:first-child { color: var(--rust); }

/* ---------- manifest table ---------- */
.manifest-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.manifest-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
}

.manifest-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-on-ink-dim);
}

.table-wrap {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--radius);
  overflow: hidden;
}

.manifest-table {
  width: 100%;
  border-collapse: collapse;
}

.manifest-table thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-on-ink-dim);
  padding: 12px 16px;
  border-bottom: 1px dashed var(--ink-600);
}

.manifest-table tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--ink-700);
  vertical-align: middle;
}

.manifest-table tbody tr:last-child td { border-bottom: none; }
.manifest-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.col-code { width: 70px; }
.col-size { width: 100px; }
.col-date { width: 160px; }
.col-actions { width: 140px; text-align: right; }

.cell-code {
  font-family: var(--font-mono);
  color: var(--amber);
  font-weight: 600;
}

.cell-name {
  word-break: break-all;
}

.cell-mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-on-ink-dim);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-on-ink-dim);
}

.empty-state p { margin: 0; }
.empty-sub { font-size: 13px; margin-top: 6px !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--text-on-ink);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
  z-index: 50;
}
.toast.error { border-color: var(--rust); color: #f4c9c0; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .col-date { display: none; }
  .app { padding: 20px 14px 60px; }
  .topbar { flex-wrap: wrap; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================
   CHAT THẾ GIỚI (widget nổi, góc dưới phải)
   ============================================================ */
.chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.chat-toggle {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--ink-600);
  background: var(--amber);
  color: var(--ink-900);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-toggle:hover { background: var(--amber-dark); }

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--rust);
  color: var(--text-on-ink);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink-900);
}

.chat-panel {
  width: min(340px, calc(100vw - 40px));
  height: min(480px, calc(100vh - 120px));
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ink-600);
  background: var(--ink-900);
}

.chat-eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--amber);
}

.chat-title {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 17px;
}

.chat-head-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.chat-status {
  margin: 0;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-on-ink-dim);
  border-bottom: 1px solid var(--ink-700);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  margin: auto 0;
  text-align: center;
  color: var(--text-on-ink-dim);
  font-size: 13px;
}

.chat-msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-msg.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-meta {
  display: flex;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-on-ink-dim);
}

.chat-msg-name { color: var(--amber); font-weight: 600; }

.chat-msg-bubble {
  background: var(--ink-700);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.mine .chat-msg-bubble {
  background: var(--amber-dark);
  color: var(--ink-900);
}

/* ---------- khối code trong chat ---------- */
.chat-code-block {
  position: relative;
  width: 100%;
  max-width: 100%;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: var(--radius);
  padding: 10px 10px 10px 12px;
  overflow-x: auto;
}

.chat-code-block code {
  display: block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-on-ink);
  white-space: pre;
  padding-right: 34px;
}

.chat-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--ink-600);
  background: var(--ink-800);
  color: var(--text-on-ink-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.chat-code-copy:hover { color: var(--amber); border-color: var(--amber); }
.chat-code-copy.copied { color: var(--amber); border-color: var(--amber); }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--ink-600);
  background: var(--ink-900);
}

.chat-code-toggle {
  flex-shrink: 0;
  font-family: var(--font-mono);
  height: 40px;
}
.chat-code-toggle[aria-pressed="true"] {
  background: var(--amber);
  color: var(--ink-900);
  border-color: var(--amber);
}

.chat-form input,
.chat-form textarea {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--ink-600);
  background: var(--ink-800);
  color: var(--text-on-ink);
  font-size: 13.5px;
}
.chat-form input:focus-visible,
.chat-form textarea:focus-visible { outline: 2px solid var(--amber); }

.chat-input-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  resize: vertical;
  min-height: 40px;
  max-height: 140px;
  white-space: pre;
  overflow: auto;
}

.chat-form button[type="submit"] {
  flex-shrink: 0;
  padding: 10px 16px;
  height: 40px;
}

@media (max-width: 640px) {
  .chat-widget { right: 14px; bottom: 14px; }
  .chat-panel { width: calc(100vw - 28px); height: min(70vh, 520px); }
}
