:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c8d3e1;
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8eefc;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #047857;
  --success-soft: #ecfdf5;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, Arial, sans-serif;
  line-height: 1.5;
}

a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  color: var(--primary-hover);
}

.admin-login {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel,
.notice,
.editor-section,
.admin-header {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  gap: 18px;
  width: min(100%, 420px);
  padding: 32px;
}

.login-panel h1,
.admin-header h1,
.editor-section h2 {
  margin: 0;
  color: var(--ink);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: 28px;
}

.login-panel p {
  margin: 0;
}

.login-panel .button {
  width: 100%;
}

.login-panel p,
.admin-header p,
.help,
.notice {
  color: var(--muted);
}

.help {
  margin: 0;
  font-size: 14px;
}

.help code {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-muted);
  font-size: 13px;
  text-transform: none;
}

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

.admin-sidebar {
  position: sticky;
  top: 0;
  display: grid;
  height: 100vh;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  padding: 20px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #0f172a;
}

.admin-brand {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
}

.admin-sidebar nav {
  display: grid;
  align-content: start;
  gap: 4px;
}

.admin-sidebar nav a,
.sidebar-actions a {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  border-radius: 6px;
  padding: 9px 11px;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 700;
}

.admin-sidebar nav a span {
  width: 4px;
  height: 20px;
  border-radius: 999px;
  background: transparent;
}

.admin-sidebar nav a:hover,
.sidebar-actions a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.admin-sidebar nav a.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.admin-sidebar nav a.is-active span {
  background: #93c5fd;
}

.sidebar-actions {
  display: grid;
  gap: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 16px;
}

.admin-main {
  display: grid;
  width: min(1120px, calc(100% - 40px));
  gap: 20px;
  margin: 24px auto 72px;
}

.admin-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: start;
  padding: 24px;
}

.admin-header p {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-header h1 {
  font-size: clamp(28px, 4vw, 40px);
}

.admin-header span {
  display: block;
  max-width: 760px;
  margin-top: 8px;
  color: var(--muted);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.header-meta strong {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
}

.header-meta strong:first-child {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #c7d7fb;
}

body.has-unsaved-changes [data-save-state] {
  color: #92400e;
  border-color: #fed7aa;
  background: #fff7ed;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.notice {
  padding: 14px 16px;
  border-left: 4px solid var(--success);
  color: var(--success);
  background: var(--success-soft);
}

.notice.error {
  color: var(--danger);
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.editor-section {
  padding: 24px;
}

.section-top {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.section-top h2 {
  font-size: 22px;
}

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

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

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 12px 13px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

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

input:focus,
textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}

input[type="file"] {
  padding: 10px;
  background: var(--surface-muted);
}

.image-field {
  display: grid;
  gap: 10px;
}

.upload-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--muted);
  background: var(--surface-muted);
  text-align: center;
}

.repeat-list {
  display: grid;
  gap: 16px;
  counter-reset: admin-row;
}

.repeat-row {
  position: relative;
  display: grid;
  gap: 18px;
  counter-increment: admin-row;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 54px 18px 18px;
  background: #fff;
}

.repeat-row::before {
  position: absolute;
  top: 14px;
  left: 18px;
  display: inline-grid;
  min-width: 34px;
  height: 22px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  content: counter(admin-row, decimal-leading-zero);
  font-size: 11px;
  font-weight: 800;
}

.inquiry-card {
  grid-template-columns: 1fr;
}

.inquiry-name {
  color: var(--primary);
  font-size: 18px;
}

.inquiry-meta {
  color: var(--muted);
  font-size: 14px;
}

.inquiry-body {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--ink);
  background: var(--surface-muted);
}

.admin-record-form {
  display: grid;
  gap: 18px;
}

.record-actions {
  display: flex;
  justify-content: flex-end;
}

.record-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.record-filter-actions,
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.record-count {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.record-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.record-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.record-table th,
.record-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.record-table th {
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.record-table tr:last-child td {
  border-bottom: 0;
}

.record-table td strong,
.record-table td span {
  display: block;
}

.record-table td span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.record-detail-row td {
  display: table-cell;
  color: var(--muted);
  background: #fbfdff;
  font-size: 13px;
}

.record-detail-row strong {
  display: inline;
  margin-right: 4px;
  color: var(--ink);
}

.record-detail-row strong:not(:first-child) {
  margin-left: 16px;
}

.text-danger-button {
  border: 0;
  padding: 0;
  color: var(--danger);
  background: transparent;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.text-danger-button:hover {
  color: #991b1b;
  text-decoration: underline;
}

.pagination {
  align-items: center;
  justify-content: flex-end;
  margin-top: 16px;
}

.pagination-page {
  display: inline-grid;
  min-width: 42px;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
  font-weight: 800;
}

.pagination-page:hover,
.pagination-page.is-active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.add-row,
.remove-row,
.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.button {
  border: 1px solid var(--primary);
  color: #fff;
  background: var(--primary);
}

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

.button.secondary,
.button.light,
.add-row {
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: #fff;
}

.button.secondary:hover,
.button.light:hover,
.add-row:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.add-row {
  width: 100%;
  margin-top: 16px;
  border-style: dashed;
}

.remove-row {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  min-height: 32px;
  border: 1px solid transparent;
  color: var(--danger);
  background: var(--danger-soft);
}

.remove-row:hover {
  border-color: #fecaca;
  color: #991b1b;
  background: #fee2e2;
}

.form-footer {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  justify-content: flex-end;
  padding: 18px 0 0;
  background: linear-gradient(rgba(246, 248, 251, 0), rgba(246, 248, 251, 0.96) 38%, var(--bg));
}

.form-footer .button {
  min-width: 190px;
}

.admin-mobile-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  background: #fff;
}

.admin-nav-toggle {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.admin-nav-toggle span {
  position: absolute;
  left: 10px;
  display: block;
  width: 20px;
  height: 2px;
  background: var(--primary);
  transition: transform 160ms ease;
}

.admin-nav-toggle span:nth-child(1) {
  top: 15px;
}

.admin-nav-toggle span:nth-child(2) {
  top: 24px;
}

.admin-nav-toggle.is-open span:nth-child(1) {
  transform: translateY(4.5px) rotate(45deg);
}

.admin-nav-toggle.is-open span:nth-child(2) {
  transform: translateY(-4.5px) rotate(-45deg);
}

@media (max-width: 960px) {
  .admin-mobile-header {
    display: flex;
  }

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

  .admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 150;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 220ms ease;
  }

  .admin-sidebar.is-open {
    transform: translateX(0);
  }

  .admin-brand {
    margin-top: 52px;
  }

  .admin-main {
    width: min(100% - 24px, 1120px);
    margin-top: 16px;
  }
}

@media (max-width: 760px) {
  .login-panel,
  .admin-header,
  .editor-section {
    padding: 18px;
  }

  .admin-header,
  .section-top {
    display: grid;
  }

  .admin-header {
    grid-template-columns: 1fr;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions .button {
    width: 100%;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .record-actions {
    justify-content: stretch;
  }

  .record-actions .button {
    width: 100%;
  }

  .record-filter {
    grid-template-columns: 1fr;
  }

  .record-filter-actions .button {
    flex: 1;
  }

  .pagination {
    justify-content: flex-start;
  }

  .record-table-wrap {
    border: 0;
    background: transparent;
  }

  .record-table,
  .record-table thead,
  .record-table tbody,
  .record-table tr,
  .record-table th,
  .record-table td {
    display: block;
  }

  .record-table thead {
    display: none;
  }

  .record-table tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
  }

  .record-table td {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }

  .record-table td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .record-detail-row td {
    display: block;
  }

  .record-detail-row td::before {
    content: none;
  }

  .record-detail-row strong {
    display: block;
    margin: 10px 0 2px;
  }

  .record-detail-row strong:not(:first-child) {
    margin-left: 0;
  }

  .form-footer .button {
    width: 100%;
  }
}
