:root {
  --ink: #17211d;
  --muted: #68736d;
  --line: #d9dfdb;
  --paper: #f5f7f4;
  --surface: #ffffff;
  --green: #176b4d;
  --green-dark: #0e5139;
  --green-soft: #e5f2eb;
  --amber: #dca435;
  --danger: #b42318;
  --danger-soft: #fef0ee;
  --shadow: 0 18px 45px rgba(29, 48, 39, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(#cbd4cf 0.7px, transparent 0.7px);
  background-size: 16px 16px;
  font-family: "Be Vietnam Pro", sans-serif;
  font-size: 14px;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px max(24px, calc((100vw - 1320px) / 2));
  background: var(--ink);
  color: white;
  border-bottom: 4px solid var(--amber);
}
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--amber);
  color: var(--ink);
  font: 700 21px "IBM Plex Mono", monospace;
}
h1, h2, p { margin: 0; }
h1 { font-size: 18px; font-weight: 700; }
.topbar p { margin-top: 3px; color: #bfc8c3; font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.top-logout { border-color: #53625b; background: transparent; color: #d9e0dc; }
.top-logout:hover { border-color: #87958e; background: #26332d; color: white; }

main { width: min(1320px, calc(100% - 48px)); margin: 36px auto 64px; }
.bot-status-panel { display: flex; align-items: center; gap: 24px; margin-bottom: 18px; padding: 20px 24px; border: 1px solid var(--line); border-left: 4px solid var(--amber); background: var(--surface); box-shadow: 0 10px 28px rgba(29, 48, 39, .08); }
.bot-status-copy { min-width: 280px; display: flex; align-items: center; gap: 15px; flex: 1; }
.bot-status-copy .eyebrow { margin-bottom: 4px; }
.bot-status-copy h2 { font-size: 17px; }
.bot-status-copy p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.status-indicator { width: 12px; height: 12px; flex: 0 0 auto; border-radius: 50%; background: #919b96; box-shadow: 0 0 0 5px #edf0ee; }
.status-indicator[data-status="online"] { background: #1f9d68; box-shadow: 0 0 0 5px #e1f4eb; }
.status-indicator[data-status="error"], .status-indicator[data-status="offline"] { background: var(--danger); box-shadow: 0 0 0 5px var(--danger-soft); }
.status-indicator[data-status="starting"], .status-indicator[data-status="starting_login"], .status-indicator[data-status="authenticating"], .status-indicator[data-status="generating_qr"], .status-indicator[data-status="restarting"] { background: var(--amber); box-shadow: 0 0 0 5px #fbf1dc; animation: status-pulse 1.5s ease-in-out infinite; }
.qr-login { display: flex; align-items: center; gap: 14px; padding-left: 22px; border-left: 1px solid var(--line); }
.qr-login img { width: 128px; height: 128px; display: block; object-fit: contain; border: 1px solid var(--line); background: white; }
.qr-login div { max-width: 230px; display: flex; flex-direction: column; gap: 5px; }
.qr-login span { color: var(--muted); font-size: 12px; line-height: 1.5; }
@keyframes status-pulse { 50% { opacity: .45; } }
.workspace { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.section-head { display: flex; align-items: end; justify-content: space-between; padding: 26px 28px 20px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; margin-bottom: 7px; color: var(--green); font: 500 11px "IBM Plex Mono", monospace; }
h2 { font-size: 22px; line-height: 1.25; }
.total { display: flex; align-items: baseline; gap: 7px; color: var(--muted); }
.total strong { color: var(--ink); font: 500 24px "IBM Plex Mono", monospace; }
.total span { font-size: 12px; }

.toolbar { display: flex; gap: 12px; padding: 18px 28px; background: #fafbf9; border-bottom: 1px solid var(--line); }
.search-field { position: relative; flex: 1; max-width: 480px; }
.search-field svg { position: absolute; left: 13px; top: 50%; width: 18px; transform: translateY(-50%); color: var(--muted); }
.search-field input, dialog input, dialog textarea {
  width: 100%; border: 1px solid #cbd2ce; border-radius: 4px; background: white; color: var(--ink); outline: 0;
}
.search-field input { height: 42px; padding: 0 14px 0 42px; }
dialog input { height: 42px; padding: 0 12px; margin-top: 7px; }
dialog textarea { resize: vertical; min-height: 86px; padding: 10px 12px; margin-top: 7px; }
.search-field input:focus, dialog input:focus, dialog textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 1px solid transparent; border-radius: 4px; font-weight: 600; }
.button svg { width: 18px; height: 18px; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { border-color: #bfc8c3; background: white; color: var(--ink); }
.button.quiet { background: transparent; color: var(--muted); }
.button.danger { background: var(--danger); color: white; }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: 0.45; }

.table-frame { position: relative; min-height: 230px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 46px; padding: 0 14px; background: #f1f4f1; color: #55615b; font-size: 11px; font-weight: 600; text-align: left; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid #e5e9e6; vertical-align: top; overflow-wrap: anywhere; }
th:nth-child(1), td:nth-child(1) { width: 72px; }
th:nth-child(2), td:nth-child(2) { width: 21%; }
th:nth-child(3), td:nth-child(3) { width: 27%; }
th:nth-child(4), td:nth-child(4) { width: 24%; }
th:nth-child(6), td:nth-child(6) { width: 92px; }
tbody tr:hover { background: #fbfcfa; }
.keyword { font: 500 13px "IBM Plex Mono", monospace; color: var(--green-dark); }
.muted-cell { color: #9aa29e; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #52605a; }
.icon-button:hover { background: var(--green-soft); color: var(--green-dark); }
.icon-button.delete:hover { background: var(--danger-soft); color: var(--danger); }
.icon-button svg { width: 18px; }

.loading, .empty-state { position: absolute; inset: 46px 0 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(255,255,255,.94); color: var(--muted); }
.loading span { width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
.empty-state { flex-direction: column; }
.empty-state svg { width: 32px; height: 32px; color: var(--green); }
.empty-state strong { color: var(--ink); }
.empty-state span { font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.pagination { min-height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 12px 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.pagination > div { display: flex; gap: 4px; }

body:has(dialog[open]) { overflow: hidden; }
dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 6px; color: var(--ink); box-shadow: 0 28px 70px rgba(14, 32, 23, .28); }
dialog::backdrop { background: rgba(15, 25, 20, .62); }
dialog form { padding: 26px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 22px; }
dialog label:not(.drop-zone) { display: block; margin-top: 15px; color: #3f4b45; font-size: 12px; font-weight: 600; }
dialog label b { color: var(--danger); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 26px; }
.drop-zone { min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 1px dashed #9daba4; background: #f7faf7; cursor: pointer; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone svg { width: 34px; height: 34px; color: var(--green); }
.drop-zone span, .import-note { color: var(--muted); font-size: 12px; }
.import-note { margin-top: 14px; line-height: 1.6; }
.template-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 14px; color: var(--green); font-weight: 600; text-decoration: none; }
.template-link svg { width: 17px; }
.confirm-dialog { width: min(420px, calc(100% - 32px)); text-align: center; }
.confirm-dialog p { margin-top: 10px; color: var(--muted); line-height: 1.6; }
.danger-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 14px; background: var(--danger-soft); color: var(--danger); border-radius: 50%; }
.confirm-dialog .dialog-actions { justify-content: center; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: min(420px, calc(100% - 48px)); padding: 13px 16px; border-left: 4px solid var(--green); background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: #f97066; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-page { min-height: 100vh; background-color: var(--ink); background-image: radial-gradient(#3b4942 0.7px, transparent 0.7px); }
.login-layout { width: min(980px, calc(100% - 48px)); min-height: 100vh; display: grid; grid-template-columns: 1fr minmax(380px, 460px); align-items: center; gap: clamp(48px, 9vw, 120px); margin: 0 auto; padding: 48px 0; }
.login-intro { color: white; }
.login-intro .brand-mark { margin-bottom: 44px; }
.login-intro .eyebrow { color: var(--amber); }
.login-intro h1 { max-width: 540px; font-size: clamp(36px, 5vw, 62px); line-height: 1.08; letter-spacing: 0; }
.login-intro p { max-width: 420px; margin-top: 20px; color: #bfc8c3; line-height: 1.7; }
.login-panel { padding: 38px; border-top: 4px solid var(--amber); background: white; box-shadow: 0 24px 65px rgba(0, 0, 0, .3); }
.login-panel > div > p { margin-top: 8px; color: var(--muted); }
.login-panel form { margin-top: 30px; }
.login-panel form > label { display: block; margin: 17px 0 7px; color: #3f4b45; font-size: 12px; font-weight: 600; }
.login-input { position: relative; }
.login-input > svg { position: absolute; left: 13px; top: 50%; width: 18px; color: var(--muted); transform: translateY(-50%); }
.login-input input { width: 100%; height: 46px; padding: 0 44px 0 42px; border: 1px solid #cbd2ce; border-radius: 4px; color: var(--ink); outline: 0; }
.login-input input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.password-toggle { position: absolute; right: 5px; top: 5px; width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); }
.password-toggle svg { width: 18px; }
.login-error { margin-top: 16px; padding: 11px 12px; border-left: 3px solid var(--danger); background: var(--danger-soft); color: var(--danger); font-size: 12px; line-height: 1.5; }
.login-submit { width: 100%; margin-top: 22px; justify-content: space-between; }
.session-note { display: flex; align-items: center; gap: 7px; margin-top: 22px; color: var(--muted); font-size: 11px; }
.session-note svg { width: 16px; color: var(--green); }

@media (max-width: 760px) {
  .topbar { padding: 14px 16px; }
  .topbar p { display: none; }
  .top-actions .button { width: 42px; padding: 0; }
  .top-actions .button span { display: none; }
  main { width: calc(100% - 24px); margin: 20px auto 40px; }
  .bot-status-panel { align-items: stretch; flex-direction: column; gap: 16px; padding: 18px 16px; }
  .bot-status-copy { min-width: 0; }
  .bot-status-panel > .button { width: 100%; }
  .qr-login { padding: 16px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .qr-login img { width: 116px; height: 116px; }
  .section-head, .toolbar, .pagination { padding-left: 16px; padding-right: 16px; }
  .toolbar { align-items: stretch; }
  .toolbar .secondary { width: 42px; padding: 0; }
  .toolbar .secondary span { display: none; }
  .table-frame { overflow: visible; padding: 8px 12px; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody tr { position: relative; display: grid; grid-template-columns: 1fr; padding: 13px 52px 13px 12px; border-bottom: 1px solid var(--line); }
  td, th:nth-child(n), td:nth-child(n) { display: block; width: auto; padding: 3px 0; border: 0; }
  td:first-child { display: none; }
  td:nth-child(3):before { content: "Địa điểm: "; color: var(--muted); }
  td:nth-child(4):before { content: "Toạ độ: "; color: var(--muted); }
  td:nth-child(5):before { content: "Ghi chú: "; color: var(--muted); }
  td:last-child { position: absolute; right: 4px; top: 7px; }
  .row-actions { flex-direction: column; }
  .loading, .empty-state { inset: 0; min-height: 230px; }
  dialog form { padding: 22px 18px; }
  .login-layout { width: calc(100% - 32px); min-height: auto; grid-template-columns: 1fr; gap: 28px; padding: 32px 0; }
  .login-intro .brand-mark { margin-bottom: 28px; }
  .login-intro h1 { font-size: 34px; }
  .login-intro p { display: none; }
  .login-panel { padding: 28px 22px; }
}
