:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #1f2937;
  --muted: #64748b;
  --line: #d9e2ec;
  --line-soft: #edf2f7;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --focus: #2563eb;
  --danger: #be123c;
  --warning: #a16207;
  --radius: 8px;
  --shadow: 0 14px 35px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Kanit", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header {
  background: #ffffff;
  border-bottom: 1px solid var(--line-soft);
}

.header-inner {
  padding: 18px 0 24px;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.admin-link,
.ghost-button,
.filter-chip,
.button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  text-decoration: none;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.admin-link:hover,
.ghost-button:hover,
.filter-chip:hover,
.button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.intro-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: end;
}

.eyebrow,
.category-kicker,
.updated,
.result-line,
.form-hint,
.small-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 920px;
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 4.25rem);
  line-height: 1.12;
  font-weight: 700;
}

.subtitle {
  max-width: 760px;
  margin-bottom: 10px;
  color: #475569;
  font-size: 1.12rem;
  line-height: 1.7;
}

.updated {
  margin-bottom: 0;
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.summary-item {
  min-width: 0;
  background: #ffffff;
  padding: 16px;
}

.summary-item strong {
  display: block;
  color: var(--primary-dark);
  font-size: 1.7rem;
  line-height: 1;
}

.summary-item span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.search-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 24px;
}

.search-box {
  position: relative;
  display: block;
}

.search-box input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  padding: 11px 16px 11px 46px;
  outline: none;
}

.search-box input:focus,
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.search-mark {
  position: absolute;
  left: 18px;
  top: 50%;
  width: 15px;
  height: 15px;
  border: 2px solid #64748b;
  border-radius: 50%;
  transform: translateY(-58%);
}

.search-mark::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: -5px;
  width: 8px;
  height: 2px;
  border-radius: 999px;
  background: #64748b;
  transform: rotate(45deg);
}

.main-content {
  padding: 22px 0 48px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-chip {
  min-height: 36px;
  color: #475569;
  background: #ffffff;
}

.filter-chip.is-active {
  border-color: var(--primary);
  background: #e6fffb;
  color: var(--primary-dark);
}

.result-line {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

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

.category-card {
  --accent: var(--primary);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.theme-teal { --accent: #0f766e; }
.theme-indigo { --accent: #4f46e5; }
.theme-violet { --accent: #7c3aed; }
.theme-rose { --accent: #be123c; }
.theme-amber { --accent: #b45309; }
.theme-green { --accent: #15803d; }
.theme-blue { --accent: #2563eb; }
.theme-slate { --accent: #475569; }

.category-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.category-kicker {
  margin-bottom: 6px;
}

.category-heading h2 {
  margin-bottom: 6px;
  font-size: 1.35rem;
  line-height: 1.35;
  color: #0f172a;
}

.category-heading p:last-child {
  margin-bottom: 0;
  color: #64748b;
  line-height: 1.65;
}

.category-count {
  min-width: 54px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 8px 10px;
  text-align: center;
}

.link-list {
  display: grid;
}

.link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 70px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: #ffffff;
  text-decoration: none;
}

.link-row:last-child {
  border-bottom: 0;
}

a.link-row:hover {
  background: #f8fafc;
}

a.link-row:focus-visible,
.admin-link:focus-visible,
.ghost-button:focus-visible,
.filter-chip:focus-visible,
.button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.link-main {
  min-width: 0;
}

.link-main strong {
  display: block;
  overflow-wrap: anywhere;
  color: #1e293b;
  font-weight: 600;
  line-height: 1.45;
}

.link-main small {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
  color: #64748b;
  line-height: 1.35;
}

.is-disabled {
  background: #fbfcfe;
}

.is-disabled .link-main strong {
  color: #64748b;
}

.status-badge {
  width: max-content;
  max-width: 120px;
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}

.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-draft {
  background: #fef3c7;
  color: #92400e;
}

.status-hidden {
  background: #f1f5f9;
  color: #475569;
}

.empty-state {
  margin-top: 20px;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  text-align: center;
}

.empty-state h2 {
  margin-bottom: 8px;
  font-size: 1.2rem;
}

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

.site-footer {
  border-top: 1px solid var(--line-soft);
  background: #ffffff;
  color: var(--muted);
  padding: 20px 0;
  text-align: center;
}

.auth-page,
.admin-page {
  min-height: 100vh;
}

.auth-shell {
  width: min(440px, calc(100% - 32px));
  margin: 8vh auto;
  background: #ffffff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.admin-header {
  background: #ffffff;
  border-bottom: 1px solid var(--line-soft);
}

.admin-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
}

.admin-title {
  margin: 0;
  font-size: 1.35rem;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-main {
  display: grid;
  gap: 16px;
  padding: 22px 0 48px;
}

.panel {
  background: #ffffff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.panel-heading h2,
.panel-heading h3 {
  margin-bottom: 4px;
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

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

.form-grid.three {
  grid-template-columns: 1.5fr 0.8fr 0.8fr;
}

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

.auth-shell .field + .field {
  margin-top: 12px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: #334155;
  font-weight: 600;
}

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

.field textarea {
  min-height: 74px;
  resize: vertical;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

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

.button.primary:hover {
  background: var(--primary-dark);
  color: #ffffff;
}

.button.danger {
  border-color: #fecdd3;
  background: #fff1f2;
  color: var(--danger);
}

.button.warning {
  border-color: #fde68a;
  background: #fffbeb;
  color: var(--warning);
}

.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
}

.notice.success {
  background: #ecfdf5;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.notice.error {
  background: #fff1f2;
  color: #9f1239;
  border: 1px solid #fecdd3;
}

.category-admin {
  display: grid;
  gap: 12px;
}

.category-admin + .category-admin {
  margin-top: 10px;
}

.category-admin summary {
  list-style: none;
  cursor: pointer;
}

.category-admin summary::-webkit-details-marker {
  display: none;
}

.category-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 14px;
}

.category-summary h3 {
  margin-bottom: 4px;
  font-size: 1.08rem;
}

.category-summary p {
  margin-bottom: 0;
  color: var(--muted);
}

.link-editor {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcfe;
  padding: 12px;
  margin-top: 10px;
}

.link-editor h4 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.link-editor summary {
  cursor: pointer;
}

.link-editor summary::-webkit-details-marker {
  display: none;
}

.link-editor summary h4 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.admin-search {
  margin-bottom: 12px;
}

.backup-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

@media (max-width: 900px) {
  .intro-grid,
  .category-grid {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    max-width: 520px;
  }

  .form-grid,
  .form-grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .container {
    width: min(100% - 20px, 1180px);
  }

  .topbar,
  .admin-header-inner,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .intro-grid {
    gap: 18px;
  }

  .summary-panel {
    grid-template-columns: 1fr;
  }

  .site-header .intro-grid > .summary-panel {
    display: none;
  }

  .search-shell {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .filter-chip {
    white-space: nowrap;
  }

  .category-heading,
  .link-row,
  .category-summary {
    grid-template-columns: 1fr;
  }

  .status-badge,
  .category-count {
    justify-self: start;
  }
}
