:root,
[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: #d5deea;
  --text: #0f172a;
  --muted: #5b6b82;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-text: #991b1b;
  --success: #16a34a;
  --success-text: #166534;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --input-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #121a2b;
  --surface-2: #1a2438;
  --border: #2a3650;
  --text: #eef3fb;
  --muted: #93a4bf;
  --primary: #4f8cff;
  --primary-hover: #3b76e8;
  --danger: #ef4444;
  --danger-text: #fca5a5;
  --success: #22c55e;
  --success-text: #86efac;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --input-bg: #0b1020;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--app-font-size, 18px);
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Segoe UI, system-ui, sans-serif;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

input, select, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: var(--danger-text);
}

.alert-success {
  background: rgba(22, 163, 74, 0.08);
  border: 1px solid rgba(22, 163, 74, 0.25);
  color: var(--success-text);
}

.muted { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-in_progress { background: #fef3c7; color: #b45309; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo { height: 28px; }
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-link { color: var(--primary); font-weight: 600; }

.inline-form { display: inline; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.page-narrow { max-width: 860px; }

.page-dashboard {
  max-width: none;
  width: 100%;
  padding: 1rem 1.25rem 1.5rem;
  min-height: calc(100vh - 3.5rem);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-header h1 { font-size: 1.6rem; }

.search-bar {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
  align-items: start;
}

.ticket-filters {
  padding: 1rem;
  margin-bottom: 0;
  position: sticky;
  top: 1rem;
}

.ticket-filters-title {
  font-size: 0.95rem;
  margin: 0 0 0.85rem;
}

.ticket-filters-form label {
  font-size: 0.88rem;
}

.ticket-filters-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.ticket-filters-count {
  margin: 0.75rem 0 0;
}

.dashboard-table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.dashboard-date-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.dashboard-date-filter input {
  width: auto;
  min-width: 10.5rem;
}

.data-table-filterable .data-table-sort-row th {
  padding-bottom: 0.35rem;
  vertical-align: bottom;
}

.data-table-filterable .data-table-filter-row th {
  padding-top: 0;
  padding-bottom: 0.75rem;
  vertical-align: top;
}

.data-table-filter-row input,
.data-table-filter-row select {
  width: 100%;
  min-width: 0;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
}

.data-table-filter-row .date-range {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.data-table-sortable .data-table-sort-row th,
.data-table-filterable .data-table-sort-row th {
  padding-bottom: 0.75rem;
  vertical-align: bottom;
}

.data-table-sortable .actions-col,
.data-table-filterable .actions-col {
  width: 9rem;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.sort-btn:hover,
.sort-btn.is-active {
  color: var(--primary);
}

.sort-indicator {
  font-size: 0.7rem;
}

.dashboard-content {
  min-width: 0;
}

.page-dashboard .dashboard-shell {
  min-height: calc(100vh - 9rem);
}

.page-dashboard .dashboard-table {
  min-height: calc(100vh - 10rem);
}

.page-dashboard .dashboard-table .data-table {
  font-size: 1rem;
}

.page-dashboard .dashboard-table .data-table th,
.page-dashboard .dashboard-table .data-table td {
  padding: 0.95rem 1.15rem;
}

.page-dashboard .dashboard-table .data-table th {
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .ticket-filters {
    position: static;
  }
}

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.data-table .actions { white-space: nowrap; }
.data-table .empty { text-align: center; color: var(--muted); padding: 2rem; }

.ticket-link {
  color: var(--primary);
  font-weight: 600;
}

.ticket-link:hover strong {
  text-decoration: underline;
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-logo {
  height: 28px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
}

.brand-logo-large,
.brand-large .brand-logo {
  height: 48px;
  max-width: 200px;
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-large .brand-name {
  font-size: 1.35rem;
}

.brand-center {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.brand-center .brand {
  flex-direction: column;
  text-align: center;
}

.branding-preview {
  display: flex;
  justify-content: center;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.branding-form {
  margin-bottom: 0.85rem;
}

.auth-card {
  width: min(100%, 400px);
  padding: 2rem;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.brand-logo { height: 42px; }
.brand h1 { font-size: 1.35rem; }

.stack { display: flex; flex-direction: column; gap: 1rem; }

.form-card { padding: 1.5rem; }
.form-section { display: flex; flex-direction: column; gap: 0.85rem; }
.form-section h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.span-2 { grid-column: span 2; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

.settings-section {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.settings-section h2 {
  font-size: 1rem;
  margin-bottom: 0.85rem;
}

.settings-group {
  margin-bottom: 1.5rem;
}

.settings-group-title {
  font-size: 1.1rem;
  margin: 0 0 0.35rem;
}

.settings-group-note {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}

.settings-add-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.settings-add-form input[type="text"] {
  flex: 1;
}

.settings-customer-form {
  flex-wrap: wrap;
}

.settings-customer-form input[type="text"],
.settings-customer-form input[type="email"],
.settings-customer-form input[type="tel"] {
  flex: 1 1 140px;
  min-width: 120px;
}

.settings-customer-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.settings-customer-item .muted {
  font-size: 0.85rem;
}

.settings-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.settings-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.settings-list li.is-editing {
  flex-wrap: wrap;
  align-items: flex-start;
}

.settings-item-label {
  flex: 1;
  min-width: 0;
}

.settings-item-edit-input {
  flex: 1;
  min-width: 160px;
}

.settings-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.settings-customer-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
}

.settings-customer-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.5rem;
}

.settings-customer-edit-form input {
  flex: 1 1 140px;
  min-width: 120px;
}

.settings-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 200;
  max-width: 320px;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--surface-elevated, #1a1a1a);
  color: var(--text, #fff);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.settings-toast.is-error {
  border-color: #c0392b;
}

.settings-customer-list > li {
  flex-direction: column;
  align-items: stretch;
}

.settings-list li:last-child {
  border-bottom: 0;
}

.settings-list .empty-item {
  justify-content: center;
}

.settings-note {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
  position: relative;
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.15rem 0.5rem;
}

.modal-header h3 {
  font-size: 1.05rem;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 0.5rem 1.15rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-body p {
  font-size: 0.9rem;
  line-height: 1.45;
}

.modal-file-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.modal-file-label input[type="file"] {
  font-weight: 400;
  font-size: 0.85rem;
  padding: 0.45rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

.settings-layout {
  max-width: 1100px;
}

.settings-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  align-items: start;
}

.settings-nav {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  position: sticky;
  top: 1rem;
}

.settings-nav-link {
  display: block;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.settings-nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.settings-nav-link.is-active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

[data-theme="dark"] .settings-nav-link.is-active {
  background: rgba(79, 140, 255, 0.15);
}

.settings-content {
  min-width: 0;
}

.appearance-block {
  padding-top: 0.5rem;
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.appearance-block:first-of-type {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.appearance-block h3 {
  font-size: 0.95rem;
  margin-bottom: 0.65rem;
}

.appearance-font-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.appearance-font-form select {
  width: 100%;
}

@media (max-width: 640px) {
  .appearance-font-grid {
    grid-template-columns: 1fr;
  }
}

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 240px;
}

.theme-picker-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.account-dl,
.backup-stats {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.92rem;
}

.account-dl dt,
.backup-stats dt {
  color: var(--muted);
  font-weight: 600;
}

.audit-filters .form-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.data-table-compact td,
.data-table-compact th {
  font-size: 0.85rem;
}

.log-details {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 280px;
  word-break: break-word;
}

.small {
  font-size: 0.82rem;
}

.backup-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.settings-user-form {
  margin-bottom: 0;
}

.reset-password-details {
  display: inline-block;
}

.reset-password-details summary {
  list-style: none;
  cursor: pointer;
}

.reset-password-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  min-width: 220px;
}

@media (max-width: 800px) {
  .settings-shell {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
}
