/* Văn Phòng BKF&RPM Online — Đồng bộ phong cách #1D6B4C với kho.bkfasi.online + Bot Kichi 3D */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #1D6B4C;
  --accent-hover: #15803d;
  --accent-soft: #dcfce7;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #263348;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.16);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.45;
  max-width: 100vw; overflow-x: hidden;
}
.muted-sm { color: var(--muted); font-size: 12.5px; }
.hidden { display: none !important; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { padding: 4px 8px 14px; border-bottom: 1px solid var(--border); }
.brand-pill {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: 0.05em;
  color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 999px;
}
.brand-title { font-weight: 800; font-size: 17px; margin-top: 6px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav-list { display: flex; flex-direction: column; gap: 3px; margin-top: 10px; flex: 1; }
.nav-cat { font-size: 11px; font-weight: 700; color: var(--muted); padding: 10px 10px 4px; letter-spacing: 0.05em; }
.nav-item {
  display: block; width: 100%; padding: 9px 12px; border: none; border-radius: 9px;
  background: transparent; color: var(--text); font-size: 13.5px; font-weight: 500;
  text-align: left; cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-alt); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-ext, .nav-kichi { color: var(--accent); font-weight: 600; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; }
.sidebar-actions { display: flex; gap: 6px; }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 22px; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.search-top { width: 260px; }
.pill-ok {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}

.content { padding: 18px 22px 110px; max-width: 1380px; width: 100%; margin: 0 auto; }
.screen { display: none; }
.screen.screen--active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; margin-bottom: 12px;
}
.card-head h3 { margin: 0; font-size: 15px; }
.row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.chk-inline { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chk-inline input { width: auto; }

.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: span 4; }
.fg { display: flex; flex-direction: column; gap: 4px; }
.fg label { font-size: 12px; font-weight: 600; color: var(--muted); }

input, select, textarea, .input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-alt); color: var(--text); font-family: inherit; font-size: 13.5px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.prod-pick { width: 260px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 13px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-ghost { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.tbl-wrap { overflow-x: auto; }
.data-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-tbl th, .data-tbl td { border: 1px solid var(--border); padding: 6px 7px; text-align: left; }
.data-tbl th { background: var(--surface-alt); font-weight: 700; font-size: 12px; text-align: center; white-space: nowrap; }
.data-tbl td input { padding: 5px 6px; font-size: 12.5px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.ctr { text-align: center !important; }

.totals-box {
  margin-top: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  font-size: 13.5px;
}
.totals-box .grand { font-size: 16px; color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar .input { max-width: 280px; }
.seg-tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg-btn { border: none; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #fff; }

.stack-list { display: flex; flex-direction: column; gap: 8px; }
.item-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  background: var(--surface-alt); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.item-title { font-weight: 700; font-size: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.kpi .v { font-size: 22px; font-weight: 800; color: var(--accent); }
.kpi .l { font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 150; padding: 14px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 600px; padding: 16px; box-shadow: 0 18px 40px rgba(0,0,0,0.28);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Bot Kichi Floating 3D Widget & Chat Drawer */
.kichi-fab {
  position: fixed; right: 20px; bottom: 22px; z-index: 120;
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
  user-select: none; transition: transform 0.2s ease;
}
.kichi-fab:hover { transform: translateY(-4px) scale(1.03); }
.kichi-tag {
  margin-top: -6px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.kichi-cloud {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 11px; font-size: 12px; font-weight: 600;
  box-shadow: 0 6px 18px rgba(0,0,0,0.16); margin-bottom: 4px; max-width: 210px; text-align: center;
}

.kichi-drawer {
  position: fixed; right: 20px; bottom: 20px; width: 410px; max-width: calc(100vw - 24px);
  height: 580px; max-height: calc(100vh - 90px); z-index: 140;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.28); display: flex; flex-direction: column; overflow: hidden;
}
.kichi-hdr {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface-alt);
}
.kichi-hdr-left { display: flex; align-items: center; gap: 8px; }
.kichi-title { font-weight: 800; font-size: 14px; }
.kichi-status { font-size: 11.5px; color: var(--muted); }
.kichi-cfg {
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-alt);
}
.kichi-quick {
  padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px;
  border-bottom: 1px solid var(--border);
}
.chip-btn {
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text);
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.kichi-msgs {
  flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.kmsg {
  max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.kmsg.bot { align-self: flex-start; background: var(--surface-alt); border: 1px solid var(--border); }
.kmsg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.kichi-input-bar {
  display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); background: var(--surface);
}
.kichi-input-bar .input { flex: 1; }
.btn-mic-on { background: var(--danger) !important; color: #fff !important; border-color: var(--danger) !important; }

.toast-box { position: fixed; left: 20px; bottom: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #f8fafc; padding: 10px 15px; border-radius: 9px; font-size: 13px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.25); }

/* Mobile */
.mobile-nav { display: none; }
@media (max-width: 960px) {
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-4 { grid-column: span 2; }
  .two-col, .kpi-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  input, select, textarea { font-size: 16px; }
  .sidebar { display: none; }
  .topbar { padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px; flex-wrap: wrap; }
  .search-top { width: 100%; }
  .content { padding: 12px 10px calc(90px + env(safe-area-inset-bottom, 0px)); }
  .form-grid-4, .form-grid-2, .two-col { grid-template-columns: 1fr; }
  .span-2, .span-4 { grid-column: span 1; }
  .prod-pick { width: 100%; }
  .kichi-fab { right: 12px; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); transform: scale(0.84); transform-origin: bottom right; }
  .kichi-drawer { right: 8px; left: 8px; width: auto; bottom: calc(62px + env(safe-area-inset-bottom, 0px)); height: 70vh; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 50;
  }
  .mnav-item { border: none; background: transparent; color: var(--muted); padding: 10px 2px; font-size: 10.5px; font-weight: 600; cursor: pointer; }
  .mnav-item.active { color: var(--accent); border-top: 2px solid var(--accent); }
}

/* Print A4 */
.print-area { display: none; }
@media print {
  .app-shell, .toast-box, .kichi-fab, .kichi-drawer, .modal-backdrop { display: none !important; }
  .print-area { display: block !important; color: #000; background: #fff; font-family: "Times New Roman", serif; font-size: 12.5px; padding: 8mm 10mm; }
  .p-hdr { border-bottom: 2px solid #1D6B4C; padding-bottom: 8px; margin-bottom: 10px; }
  .p-title { text-align: center; font-size: 19px; font-weight: 700; color: #1D6B4C; margin: 10px 0 4px; }
  .p-sub { text-align: center; font-size: 12px; margin-bottom: 10px; }
  .p-tbl { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12px; }
  .p-tbl th, .p-tbl td { border: 1px solid #333; padding: 5px 6px; }
  .p-tbl th { background: #e6f4ee; }
  .p-signs { display: flex; justify-content: space-between; margin-top: 24px; text-align: center; page-break-inside: avoid; }
  .p-seal { display: inline-block; margin-top: 10px; border: 3px solid #dc2626; color: #dc2626; border-radius: 50%; padding: 14px 10px; font-weight: 800; font-size: 10.5px; transform: rotate(-12deg); line-height: 1.25; }
}
