:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --text: #1d2433;
  --muted: #667085;
  --primary: #1f5eff;
  --primary-dark: #1647c9;
  --primary-soft: #eaf0ff;
  --danger: #d92d20;
  --sidebar: #0f1a33;
  --sidebar-text: #c6cfe2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 4px; font-weight: 650; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h3 { font-size: 15px; margin: 0 0 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
p { margin: 0 0 8px; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-amber { color: #b54708; }
.text-green { color: #067647; }
.mt { margin-top: 12px; }
.lead { font-size: 15px; color: var(--muted); margin: 0; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 800; font-size: 13px; letter-spacing: -.5px; }
.brand-mark.lg { width: 52px; height: 52px; font-size: 20px; border-radius: 12px; }
.nav { padding: 6px 10px; flex: 1; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8aa8; padding: 16px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-link.is-active { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-sub { display: flex; flex-direction: column; margin: 2px 0 6px 28px; border-left: 1px solid rgba(255, 255, 255, .12); }
.nav-sublink { padding: 5px 12px; color: #9fabc6; font-size: 13px; }
.nav-sublink:hover { color: #fff; text-decoration: none; }
.nav-sublink.is-active { color: #fff; font-weight: 600; box-shadow: inset 2px 0 0 var(--primary); }
.sidebar-foot { padding: 12px 20px; font-size: 11px; color: #6b7894; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu form { margin: 0; }
.user-name { font-weight: 500; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.avatar-fallback { display: inline-grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-toggle { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; }

/* Page */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { padding: 14px 18px 0; }
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-3-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 16px; }
.grid-2 > .card, .grid-3-1 > .card { margin-bottom: 16px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; line-height: 1.4; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b42318; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost-danger { border-color: transparent; background: transparent; color: var(--danger); }
.btn-ghost-danger:hover { background: #fef3f2; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-google { width: 100%; justify-content: center; padding: 11px 16px; font-size: 15px; }
form.inline { display: inline; margin: 0; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
label.check.inline { display: inline-flex; }
input[type=text], input[type=email], input[type=search], input[type=date], input[type=number], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=file] { font: inherit; font-weight: 400; }
textarea { resize: vertical; }
.w-sm { width: 80px !important; }
.w-half { max-width: 320px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-weight: 450; font-size: 12.5px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-inline label { min-width: 220px; }
.row-inline { display: flex; gap: 8px; }
.select-filter { margin-bottom: 4px; }
.case-info { min-height: 1em; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 14px 16px; }
.filters label { flex: 0 1 160px; font-size: 12px; color: var(--muted); }
.filters label.grow { flex: 1 1 240px; }
.filters input, .filters select { padding: 6px 8px; }
.filter-actions { display: flex; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 4px 10px; font-weight: 600; font-size: 12.5px; align-self: center; }
.chip a { font-size: 16px; line-height: 1; color: inherit; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-value.big { font-size: 26px; }
.summary-card { display: flex; flex-direction: column; gap: 6px; }
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress span { display: block; height: 100%; background: #12b76a; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th.right, .table td.right { text-align: right; }
.table thead th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tfoot th { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table.hover tbody tr[data-href] { cursor: pointer; }
.table.hover tbody tr:hover { background: #f8faff; }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table tr.is-muted td { color: var(--muted); }
.empty-row { text-align: center !important; color: var(--muted); padding: 32px !important; }
.title-cell { min-width: 260px; }
.details-cell { max-width: 420px; word-break: break-all; }

/* Details */
.details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; }
.details dt { font-size: 12px; color: var(--muted); }
.details dd { margin: 2px 0 0; font-weight: 550; }
.remarks { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.meta { margin-top: 16px; margin-bottom: 0; }
.danger-zone { margin-top: 8px; }

/* Badges & alerts */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f2f4f7; color: #344054; white-space: nowrap; }
.badge-grey { background: #f2f4f7; color: #475467; }
.badge-blue { background: #eaf0ff; color: #1647c9; }
.badge-teal { background: #e6f7f5; color: #0e7468; }
.badge-green { background: #ecfdf3; color: #067647; }
.badge-amber { background: #fffaeb; color: #b54708; }
.badge-red { background: #fef3f2; color: #b42318; }
.badge-purple { background: #f4f3ff; color: #5925dc; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-ok { background: #12b76a; }
.dot-bad { background: var(--danger); }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.alert-error { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.alert-info { background: #eff8ff; border-color: #b2ddff; color: #175cd3; }
.log { background: #0f1a33; color: #d0d8ea; padding: 12px; border-radius: 8px; font: 12px/1.6 var(--mono); white-space: pre-wrap; max-height: 360px; overflow: auto; margin: 0; text-align: left; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* Home tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.tile { display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.tile-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); flex: none; }
.tile-icon .icon { width: 22px; height: 22px; }
.tile-body { display: flex; flex-direction: column; gap: 4px; }
.tile-title { font-weight: 650; font-size: 16px; }
.tile-desc { color: var(--muted); font-size: 13px; }
.tile-stats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.tile-stats strong { color: var(--text); }
.empty { text-align: center; padding: 40px 20px; }
.error-code { font-size: 48px; justify-content: center; color: var(--muted); }

/* Inline popover (restore) */
.inline-menu { display: inline-block; position: relative; }
.inline-menu summary { list-style: none; }
.inline-menu summary::-webkit-details-marker { display: none; }
.popover { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(16, 24, 40, .15); padding: 14px; text-align: left; white-space: normal; }

/* Pagination */
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); }
.pager { display: flex; gap: 6px; }

/* Guest */
body.guest { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #0f1a33 0%, #1d3270 100%); }
.guest-wrap { width: 100%; max-width: 400px; padding: 16px; }
.login-card { padding: 32px 28px; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { justify-content: center; margin-top: 12px; }
.dev-login { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 8px; }

/* DD/MM/YYYY date box */
.date-wrap { position: relative; display: block; }
.date-wrap input[data-date] { padding-right: 34px; }
.date-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--muted); padding: 4px; cursor: pointer; display: inline-flex; border-radius: 6px; }
.date-btn:hover { color: var(--primary); background: var(--primary-soft); }
.date-btn .icon { width: 16px; height: 16px; }
.date-picker { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* Duplicate warnings */
.filter-check { flex: 0 0 auto !important; align-self: center; color: var(--text) !important; font-size: 12.5px !important; }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.dup-box { border: 1px solid #fedf89; background: #fffaeb; color: #93370d; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.dup-box ul { margin: 6px 0 0; padding-left: 18px; }
.dup-hint { font-size: 12.5px; color: #b54708; font-weight: 500; }
.dup-hint:empty { display: none; }

/* User permissions */
.perm-head { font-size: 14px; }
.perm-body { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.perm-body.is-off { opacity: .45; }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
.presets { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
[hidden] { display: none !important; }
@media (max-width: 760px) { .perm-grid { grid-template-columns: 1fr; } }

/* Softcopy drop box */
.dropbox { border: 1.5px dashed #c3cad8; border-radius: var(--radius); padding: 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.dropbox.has-error { border-color: var(--danger); }
.dropbox.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropbox-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.dropbox .file-name { font-size: 13px; color: var(--text); font-weight: 500; }

/* Import */
.import-table td, .import-table th { font-size: 12.5px; padding: 7px 10px; }
.import-table tr.is-skip td { color: var(--muted); text-decoration: line-through; }
.warn-list { margin: 6px 0 0; padding-left: 18px; }

/* Install wizard */
.install-wrap { width: 100%; max-width: 720px; padding: 32px 16px; }
.install-head { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 18px; }
.install-title { font-size: 20px; font-weight: 650; }
.install-sub { font-size: 13px; color: #b9c4dd; }
.install-steps { list-style: none; display: flex; gap: 6px; padding: 0; margin: 0 0 14px; flex-wrap: wrap; }
.install-steps li { display: flex; align-items: center; gap: 8px; color: #9fabc6; font-size: 13px; font-weight: 550; padding: 6px 12px 6px 6px; border-radius: 999px; background: rgba(255, 255, 255, .06); }
.install-steps li span { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: rgba(255, 255, 255, .12); font-size: 12px; }
.install-steps li.is-current { color: #fff; background: rgba(255, 255, 255, .14); }
.install-steps li.is-current span { background: var(--primary); }
.install-steps li.is-done { color: #c8f5dc; }
.install-steps li.is-done span { background: #12b76a; color: #fff; }
.install-card { padding: 28px; }
.install-card h2 { margin: 0 0 6px; font-size: 20px; }
.install-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.install-actions .btn-primary { margin-left: auto; }
.howto { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; font-size: 13.5px; }
.howto ol { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.copy-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.copy-row code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 6px 8px; font-size: 12.5px; background: var(--surface); }
.key-row code { font-size: 13px; padding: 10px; }
.checks td { padding: 8px 6px; }
.dot-warn { background: #f79009; }
.text-red { color: #b42318; }
.btn.is-disabled { opacity: .45; pointer-events: auto; cursor: not-allowed; }

@media (max-width: 960px) {
  .grid-3-1, .grid-3 { grid-template-columns: 1fr; }
  .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.is-open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .menu-toggle { display: inline-flex; }
  .user-name { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters label { flex: 1 1 140px; }
  .form-inline label { min-width: 0; flex: 1 1 100%; }
}
