:root {
  --primary: #467b96;
  --accent: #f2b705;
  --sidebar: #292d33;
  --background: #f5f5f5;
  --panel: #ffffff;
  --text: #333333;
  --muted: #8a8f98;
  --border: #e5e5e5;
  --danger: #d94b4b;
  --success: #2e9f6e;
  --shadow: 0 1px 8px rgba(41, 45, 51, 0.08);
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: #ffffff;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--accent);
  color: #1f2429;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 28px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1,
.panel h2,
.drawer h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  text-decoration: none;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}

.button.primary {
  background: var(--accent);
  color: #252525;
  font-weight: 700;
}

.button.primary:hover {
  background: #dca700;
}

.button.secondary {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text);
}

.button.secondary:hover,
.button.ghost:hover {
  border-color: #d5d5d5;
  background: #f9f9f9;
}

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

.link-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
}

.icon-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card,
.panel,
.auth-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 16px;
}

.stat-card span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.split-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 {
  font-size: 16px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid,
.filters,
.user-form {
  display: grid;
  gap: 10px;
  align-items: end;
}

.form-grid {
  grid-template-columns: minmax(220px, 0.7fr) minmax(260px, 1fr) auto;
}

.filters {
  grid-template-columns: 180px 150px 160px minmax(220px, 1fr) auto;
  margin-bottom: 12px;
}

.user-form {
  grid-template-columns: 160px 180px 180px 140px minmax(240px, 1fr) auto;
}

label {
  display: grid;
  gap: 6px;
  color: #60656e;
  font-size: 12px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: #60656e;
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  min-height: 36px;
  padding: 8px 10px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(70, 123, 150, 0.12);
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.site-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.site-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.token-line,
.snippet {
  overflow: auto;
  border-radius: 6px;
  background: #f6f7f8;
  color: #343a40;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.token-line {
  padding: 8px;
  white-space: nowrap;
}

.snippet {
  max-height: 132px;
  margin-top: 10px;
  padding: 10px;
}

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

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  align-items: center;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 6px 9px;
  color: #444;
  font-size: 12px;
}

.checkbox-pill input {
  width: auto;
  min-height: auto;
  margin: 0;
  padding: 0;
}

.user-list {
  display: grid;
  gap: 10px;
}

.user-card {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) 120px 120px minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.user-card h3 {
  margin: 0 0 3px;
  font-size: 14px;
}

.user-card select,
.user-card input {
  min-height: 34px;
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: #ffffff;
}

.compact-item strong {
  font-size: 13px;
}

.compact-meta {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #686e76;
  font-size: 12px;
  font-weight: 700;
  background: #fafafa;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #fff9e2;
}

.ticket-content {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.badge.pending {
  background: #fff3c2;
  color: #7a5a00;
}

.badge.processing {
  background: #e4f0ff;
  color: #24639b;
}

.badge.resolved {
  background: #e1f6ec;
  color: #16724b;
}

.badge.rejected {
  background: #eeeeee;
  color: #5f6368;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(245, 245, 245, 0.9);
  z-index: 50;
}

.auth-overlay.visible {
  display: grid;
}

.auth-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
}

.auth-brand {
  margin-bottom: 18px;
}

.auth-brand span {
  color: var(--muted);
}

.auth-panel input {
  margin-bottom: 10px;
}

.error-text {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(41, 45, 51, 0.12);
  transform: translateX(105%);
  transition: transform 0.2s ease;
  z-index: 40;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.drawer-body {
  overflow: auto;
  padding: 18px;
}

.detail-grid {
  display: grid;
  gap: 12px;
}

.detail-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  font-size: 13px;
}

.detail-row span:first-child {
  color: var(--muted);
}

.detail-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-images img {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.event-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.event-item {
  border-left: 3px solid var(--accent);
  background: #fafafa;
  padding: 8px 10px;
  font-size: 12px;
}

.drawer-form {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sites-table th,
.sites-table td {
  white-space: nowrap;
}

.sites-table td.origins-cell {
  white-space: normal;
  max-width: 280px;
  color: #555;
}

.sites-table .col-actions {
  text-align: right;
}

.sites-table .col-actions .link-button + .link-button {
  margin-left: 12px;
}

.token-cell {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  border-radius: 4px;
  background: #f6f7f8;
  color: #343a40;
  padding: 3px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.modal.visible {
  display: flex;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(31, 36, 41, 0.45);
  z-index: 1;
}

.modal-panel {
  position: relative;
  z-index: 2;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(31, 36, 41, 0.18);
  overflow: hidden;
}

.modal-panel.modal-wide {
  width: min(720px, calc(100vw - 32px));
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  display: grid;
  gap: 12px;
  padding: 18px;
  overflow: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.skill-prompt {
  max-height: 50vh;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 6px;
  background: #1f2429;
  color: #ffffff;
  padding: 10px 14px;
  font-size: 13px;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 80;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
  }

  .nav {
    display: flex;
    margin-top: 0;
    overflow: auto;
  }

  .sidebar-foot {
    margin-top: 0;
    border-top: 0;
  }

  .stats-grid,
  .split-layout,
  .form-grid,
  .filters,
  .user-form,
  .user-card {
    grid-template-columns: 1fr;
  }
}
