:root {
  --ui-scale: 1.2;
  --sidebar-width: 312px;
  --blue-900: #071a3d;
  --blue-700: #0b244b;
  --blue-600: #1d4f9c;
  --blue-500: #2f6fcd;
  --blue-100: #dbeafe;
  --blue-50: #eff6ff;
  --ink: #0f1f3d;
  --text: #43526f;
  --mute: #8792aa;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --sidebar-bg: #ffffff;
  --border: #e8ecf1;
  --border-light: #f0f2f5;
  --danger: #d32f2f;
  --warning: #f57c00;
  --shadow-sm: 0 8px 24px rgba(15, 31, 61, 0.05);
  --shadow: 0 18px 48px rgba(15, 31, 61, 0.08);
  --radius: 24px;
  --radius-lg: 32px;
  --radius-xl: 38px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Inter", "PingFang HK", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── App Shell ── */

.app-body {
  height: 100vh;
  min-height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 18px;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 22px;
}

/* ── Sidebar ── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 29px 19px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  margin-bottom: 19px;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  color: var(--blue-700);
}

.brand-mark svg,
.brand-mark img {
  width: 26px;
  height: 26px;
}

.brand-mark img {
  display: block;
  object-fit: contain;
}

.brand-text {
  display: grid;
  gap: 2px;
}

.brand-text strong {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-text small {
  color: var(--mute);
  font-size: 13px;
  font-weight: 500;
}

.nav-section {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.nav-label {
  padding: 10px 14px 5px;
  color: var(--mute);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav {
  display: grid;
  gap: 2px;
}

.nav a,
.nav-link-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 22px;
  color: var(--text);
  font-size: 17px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
} 

.nav a:hover,
.nav-link-btn:hover {
  background: var(--blue-50);
  color: var(--blue-700);
}

.nav a.is-active {
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(18, 60, 124, 0.22);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 22px;
  height: 22px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.logout-form {
  margin: 0;
}

.nav-link-btn {
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

/* ── Topbar ── */

.main-wrapper {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: end; 
  gap: 24px;
  padding: 19px 38px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 504px;
  padding: 12px 19px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg);
}

.search-icon {
  display: grid;
  place-items: center;
  width: 22px; 
  height: 22px;
  color: var(--mute);
}
 
.search-icon svg {
  width: 19px;
  height: 19px;
}

.search-box input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  outline: none; 
}

.search-box input::placeholder {
  color: var(--mute);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 19px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px 7px 7px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 41px;
  height: 41px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}

.user-info {
  display: grid;
  gap: 1px;
}

.user-info strong {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.user-info small {
  color: var(--mute);
  font-size: 13px;
}

/* ── Main Panel ── */

.main-panel {
  display: grid;
  align-content: start;
  gap: 29px;
  padding: 34px 38px 48px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow-sm);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.page-header h1 {
  margin: 4px 0 6px;
  color: var(--ink);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
}

.eyebrow {
  color: var(--blue-700);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.muted {
  color: var(--mute);
  font-size: 17px;
  line-height: 1.5;
}

/* ── Cards ── */

.card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 29px;
  overflow: hidden;
}

.card h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
}

/* ── Stats Grid ── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
}

.stat-card {
  display: grid;
  gap: 14px;
  padding: 26px 29px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-card.is-featured {
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
}

.stat-card.is-featured .stat-label,
.stat-card.is-featured .stat-meta {
  color: rgba(255, 255, 255, 0.75);
}

.stat-card.is-featured strong {
  color: #fff;
}

.stat-card.is-featured .stat-arrow {
  color: rgba(255, 255, 255, 0.6);
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-label {
  color: var(--mute);
  font-size: 16px;
  font-weight: 500;
}

.stat-arrow {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 14px;
  background: var(--blue-50);
  color: var(--blue-700);
}

.stat-arrow svg {
  width: 17px;
  height: 17px;
}

.stat-card strong {
  color: var(--ink);
  font-size: 43px;
  font-weight: 800;
  line-height: 1;
}

.stat-meta {
  color: var(--mute);
  font-size: 14px;
}

/* ── Dashboard Grid ── */

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
}

.quick-actions {
  display: grid;
  gap: 14px;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 17px;
  padding: 17px 19px;
  border: 1px solid var(--border-light);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(15, 31, 61, 0.035);
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.quick-action:hover {
  background: var(--blue-50);
  border-color: var(--blue-100);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.quick-action-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 22px;
  background: var(--blue-50);
  color: var(--blue-700);
}

.quick-action-icon svg {
  width: 24px;
  height: 24px;
}

.quick-action-text {
  display: grid;
  gap: 2px;
}

.quick-action-text strong {
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}

.quick-action-text small {
  color: var(--mute);
  font-size: 14px;
}

.info-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.info-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 17px;
}

.info-list li:last-child {
  border-bottom: 0;
}

.info-list .info-label {
  color: var(--mute);
}

.info-list .info-value {
  color: var(--ink);
  font-weight: 600;
}

/* ── Forms ── */

.stack,
.form-grid {
  display: grid;
  gap: 22px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  padding: 13px 17px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(47, 111, 205, 0.14);
}

textarea {
  resize: vertical;
}

.html-editor-shell {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.html-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
}

.html-editor-toolbar button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 12px;
}

.html-editor-toolbar button:hover {
  background: var(--blue-50);
  border-color: var(--blue-100);
}

.html-editor {
  min-height: 360px;
  padding: 17px;
  color: var(--text);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.7;
  outline: none;
}

.html-editor:focus {
  box-shadow: inset 0 0 0 3px rgba(47, 111, 205, 0.14);
}

.html-editor p,
.html-editor h2,
.html-editor figure {
  margin: 0 0 16px;
}

.html-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 18px;
}

.html-editor-input {
  display: none;
}

.full,
.form-actions {
  grid-column: 1 / -1;
}

.checkbox-row {
  display: flex;
  align-items: center;
}

.checkbox-row input {
  width: auto;
}

/* ── Buttons ── */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  min-height: 50px;
  padding: 12px 22px;
  transition: background 0.15s, border-color 0.15s;
}

.button:hover {
  background: var(--bg);
}

.button-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
}

.button-primary:hover {
  background: linear-gradient(135deg, var(--blue-900), var(--blue-700));
}

.button-outline {
  border-color: var(--blue-700);
  color: var(--blue-700);
  background: transparent;
}

.button-outline:hover {
  background: var(--blue-50);
}

.button-danger {
  color: var(--danger);
  border-color: rgba(211, 47, 47, 0.2);
}

.button-danger:hover {
  background: rgba(211, 47, 47, 0.06);
}

.button-small {
  min-height: 41px;
  padding: 7px 14px;
  font-size: 16px;
  border-radius: 999px;
}

.page-actions {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

/* ── Alerts ── */

.alert {
  border-radius: 22px;
  padding: 14px 19px;
  font-size: 17px;
  font-weight: 500;
}

.alert-success {
  border: 1px solid rgba(18, 60, 124, 0.2);
  background: var(--blue-50);
  color: var(--blue-700);
}

.alert-error,
.field-error {
  color: var(--danger);
  font-size: 16px;
  font-weight: 500;
}

.alert-error {
  border: 1px solid rgba(211, 47, 47, 0.2);
  background: #fef2f2;
}

.toast-notice {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  min-width: 220px;
  max-width: min(360px, calc(100vw - 48px));
  border: 1px solid rgba(18, 60, 124, 0.12);
  border-radius: 20px;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  box-shadow: 0 18px 48px rgba(18, 60, 124, 0.22);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  padding: 15px 18px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast-notice.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-notice-error {
  border-color: rgba(211, 47, 47, 0.24);
  background: linear-gradient(135deg, #b91c1c, var(--danger));
  box-shadow: 0 18px 48px rgba(211, 47, 47, 0.2);
}

/* ── Tables ── */

.table-card {
  overflow-x: auto;
  padding: 0;
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border-light);
  padding: 17px 24px;
  text-align: left;
  vertical-align: middle;
  font-size: 17px;
}

th {
  color: var(--mute);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--bg);
}

td.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.actions {
  text-align: right;
}

td code {
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--blue-700);
  font-size: 16px;
}

.article-thumbnail {
  display: block;
  width: 84px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--bg);
}

.article-thumbnail-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  height: 56px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--mute);
  font-size: 13px;
  font-weight: 600;
  background: var(--bg);
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  background: var(--blue-50);
  color: var(--blue-700);
  font-size: 14px;
  font-weight: 600;
  padding: 5px 12px;
}

.badge-inactive {
  background: #f5f5f5;
  color: var(--mute);
}

.empty {
  color: var(--mute);
  text-align: center;
  padding: 38px !important;
}

/* ── Auth ── */

.auth-body {
  min-height: 100vh;
  background: var(--bg);
}

.auth-shell {
  display: grid;
  width: 100%;
  min-height: 100vh;
  place-items: center;
  padding: 29px;
}

.auth-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(1152px, 100%);
  min-height: 672px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.auth-brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 29px;
  position: relative;
  padding: 58px;
  background: linear-gradient(160deg, var(--blue-900) 0%, #000 100%);
  color: #fff;
  overflow: hidden;
}

.auth-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(112%, 620px);
  max-width: none;
  transform: translate(-50%, -50%) rotate(-18deg);
  opacity: 0.52;
  pointer-events: none;
  user-select: none;
}

.auth-brand-panel h2 {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.3;
}

.auth-brand-panel p {
  margin: 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 18px;
  line-height: 1.6;
}

.auth-features {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.auth-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 17px;
  color: rgba(255, 255, 255, 0.85);
}

.auth-features li::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.auth-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 58px;
  background: var(--surface);
}

.auth-card h1 {
  margin: 4px 0 8px;
  color: var(--ink);
  font-size: 29px;
  font-weight: 700;
}

/* ── Responsive ── */

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 14px;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 14px;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: visible;
  }

  .main-wrapper {
    overflow: visible;
  }

  .brand {
    margin-bottom: 0;
  }

  .nav-section {
    display: none;
  }

  .sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    margin-left: auto;
  }

  .topbar {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
  }

  .search-box {
    display: none;
  }

  .main-panel {
    padding: 20px 16px 32px;
    border-radius: var(--radius-lg);
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-brand-panel {
    padding: 32px;
    min-height: auto;
  }

  .auth-card {
    padding: 32px;
  }
}
