:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #9aa2ad;
  --accent: #4f8cff;
  --accent-dim: #2a4d8f;
  --danger: #ff5f6d;
  --ok: #3ecf8e;
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0; min-width: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  min-height: 100svh; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 40px; width: min(340px, 100%);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px; border-radius: 6px; border: 1px solid var(--border);
  background: #0c0e12; color: var(--text); font-size: 14px;
}
.login-card button {
  margin-top: 20px; width: 100%; padding: 10px; border-radius: 6px; border: none;
  background: var(--accent); color: white; font-weight: 600; cursor: pointer; font-size: 14px;
}
.login-card button:hover { background: var(--accent-dim); }
.error { background: rgba(255,95,109,0.15); border: 1px solid var(--danger); color: var(--danger);
  padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 8px; }
.demo-hint { margin-top: 20px; font-size: 11px; color: var(--muted); text-align: center; }
.demo-hint code { background: #0c0e12; padding: 2px 5px; border-radius: 4px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border); background: var(--panel); gap: 12px;
}
.brand { font-weight: 700; font-size: 16px; }
.who { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; min-width: 0; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0;
}
.topbar-link { color: var(--accent); text-decoration: none; font-size: 13px; }
.topbar-link:hover { text-decoration: underline; }

.tabs { display: flex; gap: 8px; padding: 16px 24px 0; }
.tab-btn {
  padding: 10px 18px; border-radius: 8px 8px 0 0; border: 1px solid var(--border); border-bottom: none;
  background: #12141a; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 500;
}
.tab-btn.active { background: var(--panel); color: var(--text); border-color: var(--accent); }
.tab-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.lock { margin-left: 6px; font-size: 11px; }

main { padding: 0 24px 40px; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 0 8px 8px 8px;
  padding: 24px; max-width: 900px; min-width: 0;
}
.panel h2 { margin-top: 0; font-size: 18px; overflow-wrap: anywhere; }
.tag { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.placeholder { color: var(--muted); font-size: 14px; padding: 20px; border: 1px dashed var(--border); border-radius: 8px; }

.job-recovery {
  margin: 16px 24px 0; max-width: 900px; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: 8px; background: #12141a;
  color: var(--muted); font-size: 12px;
}
.job-recovery strong { color: var(--text); margin-right: 8px; }
.job-recovery [data-job-recovery-list] { margin-top: 8px; }
.job-recovery-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0;
  min-width: 0; overflow-wrap: anywhere;
}
.job-recovery-item.pending { color: var(--accent); }
.job-recovery-item.complete { color: var(--ok); }
.job-recovery-item.failed,
.job-recovery-item.expired { color: var(--danger); }

.ticket-form label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 4px; }
.ticket-form input, .ticket-form textarea {
  width: 100%; padding: 9px; border-radius: 6px; border: 1px solid var(--border);
  background: #0c0e12; color: var(--text); font-size: 14px; font-family: inherit;
}
.ticket-form .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.ticket-form button {
  margin-top: 18px; padding: 10px 20px; border-radius: 6px; border: none;
  background: var(--accent); color: white; font-weight: 600; cursor: pointer; font-size: 14px;
}
.ticket-form button:disabled { opacity: 0.5; cursor: wait; }

.result { margin-top: 24px; }
.result pre {
  white-space: pre-wrap; background: #0c0e12; border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; font-size: 13px; line-height: 1.5; font-family: inherit;
  max-width: 100%; overflow-wrap: anywhere; word-break: break-word;
}
.result .error-box {
  background: rgba(255,95,109,0.12); border: 1px solid var(--danger); color: var(--danger);
  padding: 12px; border-radius: 8px; font-size: 13px;
}
.result .debug {
  margin-top: 12px; font-size: 11px; color: var(--muted); background: #0c0e12;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}
.result .debug summary { cursor: pointer; color: var(--accent); }
.result .debug pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }

.paste-zone {
  border: 1px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center;
  color: var(--muted); font-size: 13px; cursor: text; margin-top: 4px;
  overflow-wrap: anywhere;
}
.paste-zone:focus { outline: none; border-color: var(--accent); color: var(--text); }
.screenshot-previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.screenshot-thumb {
  position: relative; width: 90px; height: 90px; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border);
}
.screenshot-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.screenshot-thumb button {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6); color: white; border: none;
  border-radius: 4px; width: 18px; height: 18px; font-size: 11px; cursor: pointer; line-height: 1;
}

.admin-main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.admin-section {
  min-width: 0; margin-bottom: 20px; padding: 22px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
.admin-section h1, .admin-section h2, .admin-section h3 { margin-top: 0; }
.admin-section h1 { margin-bottom: 6px; font-size: 22px; }
.admin-section h2 { margin-bottom: 6px; font-size: 18px; }
.admin-section p { color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.section-heading {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
}
.section-heading > div { min-width: 0; }
.dataset-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.dataset-card {
  min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: #12141a;
}
.dataset-card h3 { margin-bottom: 12px; text-transform: capitalize; }
.dataset-card > strong { display: block; font-size: 26px; color: var(--accent); }
.dataset-card > span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.dataset-card dl { margin: 0; }
.dataset-card dl div { display: flex; justify-content: space-between; gap: 12px; padding-top: 7px; }
.dataset-card dt { color: var(--muted); }
.dataset-card dd { margin: 0; font-weight: 600; }
.import-form {
  display: grid; grid-template-columns: minmax(160px, 0.6fr) minmax(240px, 1.4fr) auto;
  align-items: end; gap: 12px;
}
.import-form label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.import-form input, .import-form select {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px;
  border: 1px solid var(--border); border-radius: 6px; background: #0c0e12;
  color: var(--text); font: inherit;
}
.import-form input[type="file"] { overflow: hidden; }
.admin-section button, .import-form button {
  min-height: 42px; padding: 9px 16px; border: 0; border-radius: 6px;
  background: var(--accent); color: white; font-weight: 600; cursor: pointer;
}
.admin-section button:disabled { opacity: 0.5; cursor: wait; }
.admin-section .secondary-btn {
  flex: 0 0 auto; border: 1px solid var(--border); background: #12141a; color: var(--text);
}
.admin-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.admin-section .danger-btn { background: var(--danger); }
.rollback-note { margin: 5px 0 0; font-size: 12px; }
.admin-section .small-btn { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.admin-section .outcome-more { display: block; margin-top: 12px; }
.admin-section .outcome-more[hidden] { display: none; }
.admin-message {
  margin-top: 14px; padding: 12px; border-radius: 8px; font-size: 13px; overflow-wrap: anywhere;
}
.admin-message.success-box { color: var(--ok); border: 1px solid var(--ok); background: rgba(62,207,142,0.12); }
.admin-message.error-box { color: var(--danger); border: 1px solid var(--danger); background: rgba(255,95,109,0.12); }
.count-grid {
  display: grid; grid-template-columns: repeat(5, minmax(90px, 1fr)); gap: 10px; margin: 16px 0;
}
.count-card { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #12141a; }
.count-card span { display: block; color: var(--muted); font-size: 11px; }
.count-card strong { display: block; margin-top: 3px; font-size: 20px; }
.table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.admin-table { width: 100%; min-width: 720px; border-collapse: collapse; table-layout: fixed; }
.admin-table th, .admin-table td {
  padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top;
  font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word;
}
.admin-table th { color: var(--muted); background: #12141a; font-weight: 600; }
.admin-table tr:last-child td { border-bottom: 0; }
.status-pill {
  display: inline-block; max-width: 100%; padding: 3px 7px; border-radius: 999px;
  background: rgba(79,140,255,0.15); color: var(--accent); font-size: 11px; text-transform: capitalize;
  overflow-wrap: anywhere;
}
.status-pill.accepted, .status-pill.completed { background: rgba(62,207,142,0.14); color: var(--ok); }
.status-pill.rejected, .status-pill.failed { background: rgba(255,95,109,0.14); color: var(--danger); }
.status-pill.duplicate { background: rgba(255,190,92,0.14); color: #ffbe5c; }

@media (max-width: 700px) {
  .login-card input {
    min-height: 44px;
    font-size: 16px;
  }
  .login-card button {
    min-height: 44px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: 12px;
  }
  .brand { flex: 1 1 150px; }
  .who { flex: 0 1 auto; margin-left: auto; }

  .tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 12px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  }
  .tab-btn {
    width: 100%;
    border-bottom: 1px solid var(--border);
    border-radius: 8px;
    text-align: left;
    padding: 10px 14px;
    min-height: 44px;
  }
  .tab-btn.active { border-color: var(--accent); }

  .job-recovery {
    margin: 12px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    padding: 12px;
  }
  .job-recovery strong { display: block; margin: 0 0 4px; }
  .job-recovery-item { align-items: flex-start; flex-direction: column; gap: 2px; }

  main {
    padding: 0 max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  .panel {
    border-radius: 8px;
    padding: 18px 16px;
  }
  .panel h2 { font-size: 17px; line-height: 1.35; }
  .tag {
    display: block;
    margin: 6px 0 0;
    line-height: 1.4;
  }
  .panel > p { line-height: 1.5; }
  .ticket-form .row { grid-template-columns: 1fr; gap: 0; }
  .ticket-form input, .ticket-form textarea, .ticket-form select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #0c0e12;
    color: var(--text);
    font-family: inherit;
  }
  .ticket-form textarea[name="complaint"] { min-height: 104px; }
  .ticket-form textarea[name="narrative"] { min-height: 184px; }
  .ticket-form textarea[name="ticketSet"] { min-height: 160px; }
  .ticket-form button { width: 100%; min-height: 48px; }
  .link-btn { min-height: 44px; padding: 8px 0; }
  .paste-zone { min-height: 56px; display: flex; align-items: center; justify-content: center; }
  .screenshot-thumb button { width: 28px; height: 28px; font-size: 16px; }
  .result { min-width: 0; }
  .result pre { padding: 12px; font-size: 13px; }
  .debug { min-width: 0; }

  .admin-main {
    padding: 12px max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  .admin-section { padding: 16px 12px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading button { width: 100%; }
  .dataset-summary, .import-form { grid-template-columns: 1fr; }
  .import-form input, .import-form select { min-height: 44px; font-size: 16px; }
  .import-form button { width: 100%; min-height: 48px; }
  .count-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll { overflow: visible; border: 0; }
  .admin-table, .admin-table thead, .admin-table tbody, .admin-table tr, .admin-table td {
    display: block; width: 100%; min-width: 0;
  }
  .admin-table thead { display: none; }
  .admin-table tr {
    margin-bottom: 12px; padding: 10px; border: 1px solid var(--border);
    border-radius: 8px; background: #12141a;
  }
  .admin-table td {
    min-width: 0; padding: 7px 0; border: 0; overflow-wrap: anywhere; word-break: break-word;
  }
  .admin-table td::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    color: var(--muted); font-size: 10px; font-weight: 600; text-transform: uppercase;
  }
  .admin-table td[colspan]::before { content: none; }
}

@media (max-width: 380px) {
  .login-card { padding: 28px 20px; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .who { flex-basis: 100%; justify-content: space-between; }
  .panel { padding-left: 12px; padding-right: 12px; }
}
