/* Inter variable (Latin + Vietnamese subset, SIL OFL: inter-OFL.txt). Bump ?v= when the font file changes. */
@font-face {
  font-family: "Inter";
  src: url("/assets/inter-variable.woff2?v=4.1") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --sidebar: #3f3f46;
  --sidebar-active: #27272a;
  --sidebar-card: #35353b;
  --sidebar-text: #e4e4e7;
  --page: #f4f4f5;
  --card: #ffffff;
  --border: #e4e4e7;
  --border-strong: #a1a1aa;
  --row-border: #f4f4f5;
  --head: #fafafa;
  --primary: #111111;
  --text: #18181b;
  --muted: #52525b;
  --success-bg: #e4f6ec;
  --success-text: #14653a;
  --success-dot: #1f9d55;
  --danger-bg: #fde8e8;
  --danger-text: #9b1c1c;
  --danger-dot: #d92d20;
  --danger-line: #b42318;
  --radius: 12px;
  --control: 44px;
}

* { box-sizing: border-box; }

body { margin: 0; font-family: Inter, system-ui, sans-serif; font-size: 14px; line-height: 1.5; background: var(--page); color: var(--text); }

a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .table-scroll:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.strong { font-weight: 500; }
.nowrap { white-space: nowrap; }

/* Shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; }
.brand { font-size: 20px; font-weight: 700; color: #fff; padding: 0 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.nav-link { padding: 12px; border-radius: 8px; }
.nav-link:hover { background: var(--sidebar-card); }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.admin-card { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; background: var(--sidebar-card); color: #fff; }
.admin-card.active, .admin-card:hover { background: var(--sidebar-active); }
.admin-card-text { display: flex; flex-direction: column; min-width: 0; }
.admin-card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-card-role { font-size: 12px; color: #d4d4d8; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #71717a; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; }
.avatar-lg { width: 72px; height: 72px; font-size: 24px; background: var(--sidebar-active); }
.main { padding: 24px 32px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.page-title { font-size: 24px; font-weight: 700; }
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; }
#flash:empty { display: none; }

/* Cards, alerts and notices */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.alert { padding: 12px 16px; border-radius: 8px; background: var(--danger-bg); color: var(--danger-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); font-weight: 500; }
.notice { display: flex; align-items: flex-start; gap: 16px; padding: 24px; color: var(--muted); }
.notice-title { font-weight: 600; color: var(--text); }

/* Controls */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.field-grow { flex: 1; min-width: 220px; }
.field label, .field-label { font-size: 13px; font-weight: 600; }
.field-error { font-size: 12px; color: var(--danger-line); }
input[aria-invalid="true"] { border-color: var(--danger-line); }
.readonly-box { height: var(--control); padding: 0 14px; display: flex; align-items: center; border-radius: 8px; background: var(--page); color: var(--muted); }
input, select { height: var(--control); padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
select { appearance: none; padding-right: 36px; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2352525B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.button { height: var(--control); padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.button-primary { background: var(--primary); color: #fff; }
.button-secondary { background: var(--card); border-color: var(--border-strong); color: var(--text); }
.button-danger { background: var(--card); border-color: var(--danger-line); color: var(--danger-line); }

/* Filter bar */
.filter-bar { padding: 16px; display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.filter-actions { display: flex; gap: 8px; }

/* Tables */
.list { display: flex; flex-direction: column; gap: 16px; }
.table-card { overflow: hidden; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.table-scroll { overflow-x: auto; scrollbar-width: thin; scrollbar-color: #d4d4d8 transparent; }
table { width: 100%; min-width: 640px; border-collapse: collapse; }
th { padding: 12px 16px; text-align: left; background: var(--head); border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
td { padding: 14px 16px; border-bottom: 1px solid var(--row-border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--head); }
td.clamp { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #3f3f46; }
td.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.htmx-request .table-card, .htmx-request.list { opacity: 0.6; transition: opacity 0.15s; }

/* Badges and chips */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-on { background: var(--success-bg); color: var(--success-text); }
.badge-on .badge-dot { background: var(--success-dot); }
.badge-off { background: var(--danger-bg); color: var(--danger-text); }
.badge-off .badge-dot { background: var(--danger-dot); }
.chip { display: inline-flex; padding: 2px 10px; border-radius: 99px; background: var(--page); border: 1px solid var(--border); font-size: 12px; font-weight: 500; white-space: nowrap; }
.chip-link { color: var(--text); text-decoration: none; }
.chip-link:hover { border-color: var(--border-strong); background: var(--card); }
.chip-tint { background: color-mix(in srgb, var(--tag-color) 14%, #fff); border-color: color-mix(in srgb, var(--tag-color) 45%, #fff); color: color-mix(in srgb, var(--tag-color) 55%, #18181b); }
.color-value { display: inline-flex; align-items: center; gap: 8px; }
.swatch { width: 16px; height: 16px; flex: none; border-radius: 4px; border: 1px solid var(--border); }

/* Pager */
.pager { position: sticky; bottom: 16px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 8px 12px 8px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); }
.pager-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pager-range { color: var(--muted); }
.pager-size { border-color: var(--border); padding-left: 12px; }
.pager-step, .pager-page, .pager-gap, .pager-jump button { min-width: var(--control); height: var(--control); padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; }
.pager-step:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-page[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager-gap { border-color: var(--row-border); color: var(--muted); cursor: default; }
.pager-jump { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.pager-jump input { width: 72px; padding: 0 8px; border-color: #d4d4d8; text-align: center; }
.pager-jump button { border: 0; background: transparent; font-weight: 700; }

/* Dialog */
.modal { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2); color: var(--text); }
.modal::backdrop { background: rgba(24, 24, 27, 0.45); }
.modal-form { padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-subtitle { margin-top: 2px; font-size: 13px; color: var(--muted); }
.modal-close { width: var(--control); height: var(--control); margin: -8px -8px 0 0; border: 0; border-radius: 8px; background: var(--card); color: var(--muted); font-size: 22px; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-form input[readonly] { background: var(--page); color: var(--muted); }
.modal-tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border); }
.modal-tab { min-height: var(--control); padding: 0 4px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.modal-tab[aria-selected="true"] { border-bottom-color: var(--primary); color: var(--text); }
.checks { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.checks legend { margin-bottom: 8px; padding: 0; font-size: 13px; font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--control); cursor: pointer; }
.check input { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-pair .field { min-width: 0; }
.optional { font-weight: 400; color: var(--muted); }
.switches { margin: 0; padding: 0; border: 0; }
.switches legend { margin-bottom: 4px; padding: 0; font-size: 13px; font-weight: 600; }

/* Switch: a real checkbox drawn as a 44x26 track with a 20px knob; `.switch-row` lays out name + description + switch. */
.switch { appearance: none; flex: none; position: relative; width: 44px; height: 26px; padding: 0; border: 0; border-radius: 13px; background: #d4d4d8; cursor: pointer; transition: background 0.15s; }
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch:checked { background: var(--primary); }
.switch:checked::before { transform: translateX(18px); }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::before { transition: none; } }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: var(--control); padding: 8px 0; cursor: pointer; }
.switch-row + .switch-row { border-top: 1px solid var(--row-border); }
.switch-text { display: flex; flex-direction: column; min-width: 0; }
.switch-name { font-weight: 600; }
.switch-desc { font-size: 13px; color: var(--muted); }

/* New row marker: "Mới" badge and light green row highlight (rows added by the create flow) */
.badge-new { margin-left: 8px; padding: 2px 8px; background: var(--success-bg); color: var(--success-text); }
tbody tr.row-new td, tbody tr.row-new:hover td, tbody tr.row-new td.sticky-col, tbody tr.row-new:hover td.sticky-col { background: #f0faf4; }

/* Toasts: fixed top-right stack (#toasts); entries are removed by app.js */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 1000; width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 12px; padding: 12px 8px 12px 16px; border: 1px solid #bfe6cf; border-radius: 10px; background: var(--success-bg); color: var(--success-text); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); pointer-events: auto; }
.toast-text { flex: 1; min-width: 0; padding-top: 4px; overflow-wrap: anywhere; }
.toast-close { flex: none; width: var(--control); height: var(--control); margin: -8px 0; border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: 20px; line-height: 1; cursor: pointer; }
.toast-close:hover { background: rgba(20, 101, 58, 0.1); }

/* Table actions */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sticky-col { position: sticky; right: 0; width: 76px; background: var(--card); box-shadow: -1px 0 0 var(--border); }
th.sticky-col, tbody tr:hover td.sticky-col { background: var(--head); }
.icon-button { width: var(--control); height: var(--control); display: inline-flex; align-items: center; justify-content: center; border: 1px solid #d4d4d8; border-radius: 8px; background: var(--card); color: var(--primary); cursor: pointer; }
.icon-button:hover { background: var(--page); }
.row-actions { display: flex; gap: 8px; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.table-wide { min-width: 880px; }
.chips { display: flex; gap: 6px; }
.chips-wrap { flex-wrap: wrap; }

/* Detail pages */
.page-head { display: flex; flex-direction: column; gap: 8px; }
.detail-head { display: flex; flex-direction: column; gap: 20px; }
.back-link { align-self: flex-start; min-height: var(--control); display: inline-flex; align-items: center; font-weight: 600; color: var(--muted); }
.back-link:hover { color: var(--text); }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.detail-card { max-width: 760px; padding: 32px; display: flex; flex-direction: column; gap: 20px; }
.detail-card-wide { max-width: 880px; }
.card-title { font-size: 16px; font-weight: 600; }
.card-head { padding: 20px 24px; display: flex; flex-direction: column; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border); }
.tab { padding: 12px 4px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { border-bottom-color: var(--primary); color: var(--text); }
.image-row { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 20px; padding-top: 20px; border-top: 1px solid var(--row-border); }
.image-placeholder { width: 160px; height: 160px; border-radius: 8px; background: var(--page); color: #71717a; display: flex; align-items: center; justify-content: center; }
.image-thumb { width: 160px; height: 160px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--page); overflow: hidden; cursor: zoom-in; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.image-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; min-width: 0; overflow-wrap: anywhere; }
.image-vector { display: flex; flex-direction: column; gap: 8px; }
.image-vector:empty { display: none; }
.vector-values { max-height: 160px; margin: 0; padding: 12px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--page); white-space: pre-wrap; overflow-wrap: anywhere; }
.lightbox { max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: var(--radius); background: transparent; overflow: visible; }
.lightbox::backdrop { background: rgba(24, 24, 27, 0.8); }
.lightbox img { display: block; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); border-radius: var(--radius); }
.lightbox-close { position: absolute; top: 8px; right: 8px; width: var(--control); height: var(--control); border: 0; border-radius: 8px; background: rgba(24, 24, 27, 0.7); color: #fff; font-size: 22px; cursor: pointer; }

/* Dashboard */
.dash-section { padding: 24px; display: flex; flex-direction: column; gap: 20px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.dash-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dash-head p { margin-top: 4px; }
.dash-title { font-size: 18px; font-weight: 700; }
.dash-link { min-height: var(--control); display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--primary); }
.dash-section .notice { padding: 0; border: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.tile { padding: 16px; display: flex; flex-direction: column; gap: 8px; background: var(--head); border: 1px solid var(--border); border-radius: 10px; }
.tile-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.tile-value { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-on, .meter-on { background: var(--success-dot); }
.dot-off, .meter-off { background: var(--danger-dot); }
.rate { display: flex; flex-direction: column; gap: 8px; }
.rate-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.rate-head strong { font-weight: 600; color: var(--text); }
.meter { display: flex; gap: 2px; height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.meter-lg { height: 10px; }
.meter-fill { background: var(--primary); }

/* Login */
.login { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; background: var(--card); }
.login-brand { background: #303036; color: #fff; padding: 64px; display: flex; flex-direction: column; justify-content: space-between; }
.login-brand .brand { padding: 0; }
.login-pitch { max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.login-pitch h2 { font-size: 36px; line-height: 1.2; font-weight: 700; }
.login-pitch p { font-size: 16px; line-height: 1.6; color: var(--border-strong); }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 32px 16px; background: var(--page); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 40px 32px; display: flex; flex-direction: column; gap: 24px; }
.login-heading { display: flex; flex-direction: column; gap: 8px; }
.login-heading h1 { font-size: 24px; font-weight: 700; }
.login-card .button { font-size: 15px; }

/* Profile */
.profile { max-width: 640px; padding: 32px; display: flex; flex-direction: column; gap: 24px; }
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-name { font-size: 20px; font-weight: 700; }
.details { margin: 0; display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px 24px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.profile-actions { border-top: 1px solid var(--border); padding-top: 24px; display: flex; flex-wrap: wrap; gap: 12px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .sidebar { padding: 16px; gap: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .admin-card { margin-top: 0; }
  .main { padding: 16px; }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-brand { display: none; }
}

@media (max-width: 600px) {
  .field, .field-grow { min-width: 100%; }
  .filter-actions { width: 100%; }
  .filter-actions .button { flex: 1; }
  .pager { position: static; }
  .pager-step span { display: none; }
  .pager-jump { margin-left: 0; }
  .details { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .details dd { margin-bottom: 12px; }
  .login-card { padding: 32px 20px; }
  .detail-card { padding: 20px; }
  .image-row { grid-template-columns: minmax(0, 1fr); }
  .field-pair { grid-template-columns: minmax(0, 1fr); }
  .dash-section { padding: 16px; }
}
