/* ===== Design tokens: style C "Warm brand" =====
   :root holds the dark palette; body.light-theme (the default) holds the light one.
   The sidebar keeps its deep-teal look in both modes. */
:root {
  --bg-base: #0E1716;
  --bg-surface: #152221;
  --bg-subtle: #1B2B2A;
  --bg-field: #111C1B;
  --border-color: #24403E;
  --border-strong: #31524F;
  --border-active: #F07A55;

  --text-primary: #EEF3F2;
  --text-secondary: #A9B8B6;
  --text-muted: #7C8D8B;

  --color-primary: #F07A55;
  --color-primary-hover: #F48C6A;
  --color-primary-glow: rgba(240, 122, 85, 0.14);
  --on-primary: #FFFFFF;
  --color-accent: #4FB3AE;
  --color-accent-glow: rgba(79, 179, 174, 0.14);
  --color-success: #3DBE85;
  --color-success-glow: rgba(61, 190, 133, 0.14);
  --color-warning: #E5A33B;
  --color-warning-glow: rgba(229, 163, 59, 0.16);
  --color-danger: #EF6A5A;
  --color-danger-glow: rgba(239, 106, 90, 0.14);

  --bg-sidebar: #0A2A2B;
  --sidebar-text: #D7E6E4;
  --sidebar-muted: #86A9A6;
  --sidebar-active: #164546;
  --sidebar-border: rgba(255, 255, 255, 0.08);

  --font-display: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
  --font-body: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  --shadow-glow: 0 0 0 3px var(--color-primary-glow);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

body.light-theme {
  --bg-base: #FBF8F4;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F5F0E8;
  --bg-field: #FFFDFA;
  --border-color: #EDE6DC;
  --border-strong: #DDD2C3;
  --border-active: #E8613C;

  --text-primary: #1F2A2A;
  --text-secondary: #55625F;
  --text-muted: #8A9592;

  --color-primary: #E8613C;
  --color-primary-hover: #D4532F;
  --color-primary-glow: rgba(232, 97, 60, 0.12);
  --color-accent: #0F6E6E;
  --color-accent-glow: rgba(15, 110, 110, 0.10);
  --color-success: #1F8A5B;
  --color-success-glow: rgba(31, 138, 91, 0.10);
  --color-warning: #B9741A;
  --color-warning-glow: rgba(201, 130, 27, 0.12);
  --color-danger: #C8402F;
  --color-danger-glow: rgba(200, 64, 47, 0.10);

  --bg-sidebar: #0F3D3E;
  --sidebar-active: #1D5556;

  --shadow-card: 0 1px 2px rgba(60, 40, 20, 0.04);
  --shadow-pop: 0 12px 32px rgba(60, 40, 20, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Sidebar ===== */
.sidebar {
  width: 248px;
  height: 100vh;
  background: var(--bg-sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
  overflow: hidden;
}

.brand {
  padding: 18px 18px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #FFFFFF;
  font-family: var(--font-display);
  flex-shrink: 0;
}

.brand-name h1 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: #FFFFFF;
  line-height: 1.2;
}

.brand-name p {
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.nav-menu {
  list-style: none;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 0px;
  min-height: 0;
  overflow-y: auto;
}

.nav-menu::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }

.nav-group-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}

.nav-item { display: flex; }

.nav-item button {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--sidebar-text);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 400;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-item button i {
  width: 18px;
  text-align: center;
  font-size: 0.95rem;
  color: var(--sidebar-muted);
  transition: color var(--transition-fast);
}

.nav-item button:hover { background: rgba(255, 255, 255, 0.06); color: #FFFFFF; }
.nav-item button:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }

.nav-item.active button {
  background: var(--sidebar-active);
  color: #FFFFFF;
  font-weight: 500;
}

.nav-item.active button i { color: var(--color-primary); }

.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}

.nav-backdrop { display: none; }

/* ===== Main area ===== */
.main-wrapper {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

.top-bar {
  height: 64px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 32px;
  flex-shrink: 0;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.page-title h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle { display: none; }

.system-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--color-success);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--color-success-glow);
}

.content-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 28px 32px 40px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-pane.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Cards ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.card .card {
  background: var(--bg-subtle);
  box-shadow: none;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title i { color: var(--color-primary); }
.card-title > .btn,
.card-title > button { margin-left: auto; }

/* ===== Grid ===== */
.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-aside {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 20px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-row,
.form-row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.form-row .form-group,
.form-row-2 .form-group { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  background: var(--bg-field);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="date"]:focus,
input[type="tel"]:focus,
select:focus,
textarea:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-glow);
}

select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

small { color: var(--text-secondary); }

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  user-select: none;
}

.checkbox-label input[type="checkbox"] { display: none; }

.checkbox-custom {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-field);
  display: inline-block;
  position: relative;
  transition: var(--transition-fast);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--on-primary);
  font-weight: 700;
  font-size: 0.8rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--text-muted);
}

.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-success {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #FFFFFF;
}

.btn-success:hover {
  background: var(--color-success);
  border-color: var(--color-success);
  filter: brightness(0.92);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  border-color: transparent;
  color: var(--text-primary);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ===== Post previews ===== */
.preview-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.post-preview-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 0.86rem;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--text-primary);
  position: relative;
  max-height: 380px;
  overflow-y: auto;
}

.post-preview-card.preview-line { border-left-color: var(--color-success); }
.post-preview-card.preview-alt { border-left-color: var(--color-accent); }
.post-preview-card.preview-code { font-family: var(--font-mono); font-size: 0.8rem; }

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.copy-btn:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--on-primary);
}

.section-divider {
  margin-top: 24px;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.section-head .card-title { margin-bottom: 0; font-size: 0.95rem; }

.help-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ===== Filename standardizer ===== */
.standardizer-box {
  background: var(--bg-subtle);
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  margin-top: 16px;
  text-align: center;
}

.standardized-output {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--color-accent);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  word-break: break-all;
  user-select: all;
}

/* ===== Checklists ===== */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.checklist-item:last-child { border-bottom: none; }

.checklist-text {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.checklist-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Tables / listing browser ===== */
.browser-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-input {
  flex-grow: 1;
  min-width: 200px;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.86rem;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.78rem;
}

tbody tr:hover { background: var(--bg-subtle); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.badge-blue { background: var(--color-accent-glow); color: var(--color-accent); }
.badge-purple { background: var(--color-primary-glow); color: var(--color-primary); }
.badge-green { background: var(--color-success-glow); color: var(--color-success); }
.badge-yellow { background: var(--color-warning-glow); color: var(--color-warning); }
.badge-lg { font-size: 0.92rem; padding: 6px 12px; }

/* ===== File upload ===== */
.file-upload-zone {
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-subtle);
  transition: var(--transition-fast);
  margin-bottom: 20px;
}

.file-upload-zone:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-glow);
}

.file-upload-icon {
  font-size: 2rem;
  color: var(--color-primary);
  margin-bottom: 8px;
}

.file-upload-text {
  font-weight: 500;
  font-size: 0.9rem;
}

.file-upload-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Chat assistant scripts ===== */
.script-group { margin-bottom: 24px; }

.script-header {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-accent);
  margin-bottom: 12px;
  border-left: 3px solid var(--color-accent);
  padding-left: 8px;
}

.script-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}

.script-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.script-body {
  font-size: 0.86rem;
  color: var(--text-secondary);
  white-space: pre-line;
  margin-right: 80px;
}

.brand-select-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.brand-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  transition: var(--transition-fast);
}

.brand-radio input { display: none; }

.brand-radio.active {
  border-color: var(--color-primary);
  background: var(--color-primary-glow);
  color: var(--color-primary);
}

/* ===== Chips ===== */
.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.preset-chips.is-inline { margin-bottom: 0; }

.chips-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  align-self: center;
  margin-right: 2px;
}

.chip-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-btn:hover {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.chip-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--on-primary);
}

.toolbar-card {
  padding: 12px 16px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.route-block { margin-bottom: 16px; }
.route-block:last-child { margin-bottom: 0; }

/* ===== Calculator ===== */
.calc-tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.calc-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
}

.calc-tab-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }

.calc-tab-btn.active {
  background: var(--color-primary-glow);
  border-color: transparent;
  color: var(--color-primary);
}

.calc-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.calc-stat-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
}

.calc-stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.calc-stat-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
}

.calc-stat-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Chat assistant variable bar ===== */
.variable-input-bar {
  background: var(--color-accent-glow);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.variable-input-bar h4 {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== Watermark ===== */
.wm-position-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.wm-pos-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  font-family: var(--font-body);
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: center;
}

.wm-pos-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-glow);
}

.wm-pos-btn.active {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
}

.canvas-stage {
  background: var(--bg-subtle);
}

/* ===== Photo renamer ===== */
.file-list .file-row:has(.select-file:checked) {
  border-color: var(--color-primary) !important;
  background: var(--color-primary-glow) !important;
}

#renamerPreviewList li {
  display: grid;
  grid-template-columns: 35px 1fr;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
}

#renamerPreviewList li:last-child { border-bottom: 0; }

#renamerPreviewList .order {
  color: var(--text-muted);
  font-weight: 600;
}

#renamerPreviewList .pending { color: var(--color-warning); }

.area-button {
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 8px 6px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.area-button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-glow);
}

/* ===== Combo-box dropdown ===== */
.combo-box-wrapper { position: relative; }

.combo-box-wrapper input { padding-right: 34px; }

.combo-box-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  cursor: pointer;
}

.combo-box-dropdown {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 1000;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: var(--shadow-pop);
  margin-top: 6px;
}

.combo-group-header {
  padding: 8px 12px 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.combo-option {
  padding: 8px 16px;
  font-size: 0.86rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.12s ease;
  border-bottom: 1px solid var(--border-color);
}

.combo-option:last-child { border-bottom: none; }

.combo-option:hover {
  background: var(--color-primary-glow);
  color: var(--color-primary);
}

/* ===== Auth gate ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg-base);
}
body.auth-ready .auth-screen { display: none; }
body:not(.auth-ready) .sidebar,
body:not(.auth-ready) .main-wrapper { display: none; }

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  justify-items: center;
  text-align: center;
}
.auth-card h2 { font-size: 1.15rem; font-weight: 600; }
.auth-panel { display: none; width: 100%; }
.auth-panel.active { display: grid; gap: 12px; justify-items: center; }
.auth-panel p { color: var(--text-secondary); font-size: 0.9rem; }
.auth-dev-form { display: grid; gap: 8px; width: 100%; margin-top: 12px; text-align: left; }
.auth-dev-form[hidden] { display: none; }
.auth-dev-form label { font-size: 0.82rem; color: var(--text-secondary); }
.auth-message { min-height: 1.2em; font-size: 0.85rem; color: var(--color-danger); }

/* ===== Signed-in user chip ===== */
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: 0.85rem;
  white-space: nowrap;
}
.user-chip[hidden] { display: none; }
#user-chip-switch[hidden] { display: none; }
.operator-team { justify-content: center; margin: 4px 0 0; }
.operator-team .chip-btn { font-size: 0.95rem; padding: 9px 16px; }
.staff-form .staff-shared { grid-column: 1 / -1; font-size: 0.86rem; }
body.is-offline .status-dot { background: var(--color-warning); box-shadow: 0 0 0 3px var(--color-warning-glow); }
.user-chip > i { color: var(--text-muted); font-size: 1.1rem; }

/* ===== Role-gated UI ===== */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: revert !important; }
body.is-admin .nav-item.admin-only { display: flex !important; }

/* ===== Staff management ===== */
.staff-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.staff-form .form-group { margin-bottom: 0; }
.staff-message { min-height: 1.2em; margin-top: 8px; font-size: 0.85rem; color: var(--color-success); }
.staff-message.is-error { color: var(--color-danger); }
.staff-table-wrap { overflow-x: auto; }
.staff-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.badge.staff-on { background: var(--color-success-glow); color: var(--color-success); }
.badge.staff-off { background: var(--color-danger-glow); color: var(--color-danger); }

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .grid-aside { grid-template-columns: minmax(0, 1fr); }
  .grid-3:has(> .card) { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-pop);
  }

  body.nav-open .sidebar { transform: translateX(0); }

  body.nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(10, 20, 20, 0.45);
  }

  .nav-toggle { display: inline-flex; }

  .top-bar { padding: 0 16px; height: 58px; }
  .page-title h2 { font-size: 1.05rem; }
  .status-indicator { display: none; }
  #user-chip-name, #user-chip-role { display: none; }
  .theme-toggle-label { display: none; }

  .content-body { padding: 16px 16px 32px; }
  .card { padding: 16px; border-radius: var(--radius-md); }

  .grid-2,
  .form-row,
  .form-row-2 { grid-template-columns: minmax(0, 1fr); }

  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

/* Rent billing document */
.rent-bill-paper { background:#fff; color:#172033; border-radius:12px; padding:32px; min-height:720px; box-shadow:0 12px 35px rgba(0,0,0,.2); }
.rent-bill-head { display:flex; justify-content:space-between; gap:20px; padding-bottom:20px; border-bottom:3px solid #0F3D3E; }
.rent-bill-brand { color:#0F3D3E; font-weight:800; font-size:1.25rem; letter-spacing:.04em; }
.rent-bill-head h2 { margin:0 0 6px; color:#172033; }
.rent-bill-meta { white-space:pre-line; line-height:1.8; padding:20px 0; }
.rent-bill-customer { border:1px solid #d8deea; padding:14px; margin-bottom:18px; }
.rent-bill-table { width:100%; border-collapse:collapse; margin:8px 0 24px; }
.rent-bill-table th,.rent-bill-table td { border:1px solid #d8deea; padding:11px 12px; text-align:left; }
.rent-bill-table th:last-child,.rent-bill-table td:last-child { text-align:right; }
.rent-bill-table thead { background:#F5F0E8; }
.rent-bill-table tfoot { background:#172033; color:#fff; font-size:1.05rem; }
.rent-bill-note { white-space:pre-line; background:#f5f7fb; padding:14px; border-radius:8px; }
.rent-bill-status { margin-top:18px; padding:12px; border:1px solid #f59e0b; border-radius:8px; font-weight:700; }
.rent-bill-signature { width:260px; margin:54px 0 0 auto; text-align:center; color:#172033; }
.rent-bill-signature img { display:none; max-width:220px; max-height:90px; object-fit:contain; margin:0 auto -8px; }
.rent-bill-sign-line { border-top:1px dashed #172033; margin:8px 0; }
.rent-bill-footer { margin-top:36px; padding-top:14px; border-top:1px solid #d8deea; color:#667085; font-size:.78rem; }
.bill-language-note { margin:-8px 0 16px; color:var(--text-secondary); font-size:.82rem; line-height:1.5; }
.bill-project-source { display:block; margin-top:6px; color:var(--text-secondary); font-size:.76rem; line-height:1.4; }
@page { size:A4 portrait; margin:8mm 10mm 10mm; }
@media print {
  html,body { width:210mm; height:297mm; margin:0 !important; padding:0 !important; overflow:hidden !important; background:#fff !important; }
  body * { visibility:hidden !important; }
  #rent-bill-document,#rent-bill-document * { visibility:visible !important; }
  #rent-bill-document {
    position:fixed; left:0; top:0; width:190mm; height:auto; max-height:277mm; min-height:0;
    box-sizing:border-box; margin:0; padding:4mm 10mm 6mm; box-shadow:none; border-radius:0;
    font-size:10.5pt; line-height:1.35; overflow:hidden; page-break-inside:avoid; break-inside:avoid;
  }
  .rent-bill-head { gap:8mm; padding-bottom:4mm; }
  .rent-bill-meta { line-height:1.45; padding:3.5mm 0; }
  .rent-bill-customer { padding:3mm; margin-bottom:3mm; }
  .rent-bill-table { margin:2mm 0 4mm; }
  .rent-bill-table th,.rent-bill-table td { padding:2.3mm 3mm; }
  .rent-bill-status { margin-top:3mm; padding:2.5mm 3mm; }
  .rent-bill-signature {
    width:70mm; min-height:35mm; margin:6mm 0 0 auto;
    display:flex; flex-direction:column; justify-content:flex-end;
  }
  .rent-bill-signature img { max-width:58mm; max-height:21mm; }
  .rent-bill-sign-line { margin:2mm 0 1.5mm; }
  .rent-bill-footer { margin-top:6mm; padding-top:3mm; }
}
