:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #3562e8;
  --accent-ink: #ffffff;
  --danger: #d0554d;
  --danger-bg: #fbeceb;
  --success: #1f8a5b;
  --success-bg: #e7f5ee;
  --warn: #b7791f;
  --warn-bg: #fbf3e4;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { font-size: 14.5px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex: 0 0 220px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
}
.sidebar-logo { font-size: 18px; font-weight: 700; padding: 6px 10px 18px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--ink); font-weight: 500; font-size: 14px;
}
.sidebar-link:hover { background: var(--bg); text-decoration: none; }
.sidebar-link.active { background: var(--accent); color: var(--accent-ink); }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.sidebar-user { font-size: 12.5px; color: var(--muted); padding: 0 10px 8px; word-break: break-all; }
.sidebar-logout {
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: 9px 10px; border-radius: 8px; color: var(--danger); font-weight: 500; font-size: 14px;
}
.sidebar-logout:hover { background: var(--danger-bg); }

.main { flex: 1; min-width: 0; padding: 28px 32px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink); font-weight: 600;
  font-size: 13.5px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(.95); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font: inherit; color: var(--ink);
  background: var(--panel); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { resize: vertical; font-family: inherit; }
.field-note { font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.field-row .field { flex: 1; min-width: 180px; }
.field-inline { display: flex; align-items: center; gap: 10px; }

.locked-value {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: 8px; background: var(--bg); color: var(--muted); font-weight: 600;
}

.toggle { position: relative; width: 40px; height: 22px; border-radius: 999px; border: none; cursor: pointer; background: var(--border); flex: 0 0 auto; }
.toggle.on { background: var(--accent); }
.toggle .knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle.on .knob { transform: translateX(18px); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-success .badge-dot { background: var(--success); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-warn .badge-dot { background: var(--warn); }
.badge-muted { background: var(--bg); color: var(--muted); }
.badge-muted .badge-dot { background: var(--muted); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab-btn { padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer; font-size: 12px; font-weight: 700; text-transform: uppercase; background: var(--bg); color: var(--muted); }
.tab-btn.on { background: var(--accent); color: var(--accent-ink); }

.err-text { color: var(--danger); font-size: 13px; }
.empty-state, .loading-state { padding: 40px 10px; text-align: center; color: var(--muted); }

.modal-scrim { position: fixed; inset: 0; background: rgba(20, 22, 30, .45); display: grid; place-items: center; padding: 20px; z-index: 100; overflow-y: auto; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 480px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; font-weight: 700; font-size: 15px; }
.modal-foot { display: flex; gap: 10px; margin-top: 16px; }
.iconbtn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; }
.list-row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.list-row-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.pill-nav { display: flex; gap: 8px; margin-bottom: 16px; }

/* login page */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 380px; }
.login-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 22px; }

/* chat thread (support tickets) */
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 50vh; overflow-y: auto; padding: 4px; margin-bottom: 14px; }
.bubble { max-width: 75%; padding: 10px 13px; border-radius: 12px; background: var(--bg); }
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble-meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.bubble-files { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; opacity: .85; }
