:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --text: #1d2430;
  --muted: #687384;
  --line: #d9dee7;
  --soft-line: #e8edf3;
  --accent: #256f6c;
  --accent-strong: #174f4d;
  --accent-soft: #e7f1f0;
  --warn: #a33d2e;
  --warn-bg: #fff0ed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 26px 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar form {
  margin-top: auto;
}

.brand,
.login-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand small,
.login-header p {
  display: block;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
}

.nav a.active,
.nav a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.content {
  width: min(100%, 1240px);
  padding: 32px;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1,
.login-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-card,
.panel,
.result-card,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card {
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 30px;
  line-height: 1;
}

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

.panel,
.result-card {
  padding: 18px;
}

.panel h2,
.result-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.empty {
  margin: 0;
  color: var(--muted);
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(520px, 1fr);
  gap: 18px;
  align-items: start;
}

.form-stack {
  display: grid;
  gap: 14px;
}

.form-stack label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.form-stack input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
}

.form-stack input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 111, 108, 0.12);
  outline: 0;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}

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

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

.loading-note {
  margin: 0;
  border-radius: 8px;
  background: #eef6f6;
  color: var(--accent-strong);
  padding: 10px 12px;
  font-size: 14px;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator,
.is-submitting .loading-note {
  display: block;
}

.ghost-button {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto 0;
  padding: 24px;
}

.login-header {
  margin-bottom: 24px;
}

.notice {
  margin-bottom: 14px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.notice.danger {
  border: 1px solid #f0bbb1;
  background: var(--warn-bg);
  color: var(--warn);
}

.notice.success {
  border: 1px solid #b9d7cc;
  background: #edf7f3;
  color: var(--accent-strong);
}

.result-dashboard {
  padding: 0;
  overflow: hidden;
}

.result-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--soft-line);
  background: linear-gradient(180deg, #ffffff 0%, #f7faf9 100%);
  padding: 18px 20px;
}

.result-hero h2 {
  margin: 4px 0 0;
  font-size: 24px;
}

.result-label {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.result-meta span:not(.status-pill) {
  border: 1px solid var(--soft-line);
  border-radius: 999px;
  background: #fff;
  padding: 6px 10px;
}

.result-metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--soft-line);
  background: var(--soft-line);
}

.result-metric {
  display: grid;
  gap: 5px;
  min-height: 92px;
  padding: 14px;
  background: #fff;
}

.result-metric span,
.result-metric small {
  color: var(--muted);
  font-size: 12px;
}

.result-metric strong {
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.result-card p {
  margin: 0;
  color: var(--muted);
}

.telegram-message {
  white-space: pre-wrap;
  line-height: 1.55;
}

.telegram-message b {
  color: var(--text);
}

.result-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.result-section {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.result-section-primary {
  grid-column: 1 / -1;
  border-color: #c7dad8;
  background: #f7fbfa;
}

.result-section h3 {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 14px;
  line-height: 1.35;
}

.result-section pre {
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

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

.match-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 8px 10px;
}

.match-button:hover {
  border-color: var(--accent);
}

.error-text {
  margin: 0;
  color: var(--warn);
}

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

.report-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.report-item div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.report-item span,
.report-item p {
  margin: 0;
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #e8f2f1;
  color: var(--accent-strong);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

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

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    width: 100%;
    padding: 20px;
  }

  .kpi-grid,
  .work-grid,
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .result-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-meta {
    justify-content: flex-start;
  }

  .result-metric-grid {
    grid-template-columns: 1fr;
  }

  .result-section-grid {
    grid-template-columns: 1fr;
  }
}
