:root {
  --blue-800: #0f2d5c;
  --blue-700: #163a78;
  --blue-600: #1f4b99;
  --blue-500: #2a62c3;
  --blue-50: #eef3fb;
  --grey-900: #1a1d21;
  --grey-700: #3d4652;
  --grey-600: #5c6570;
  --grey-200: #e2e6eb;
  --grey-100: #f4f6f9;
  --white: #fff;
  --danger: #b42318;
  --success: #067647;
  --sidebar-w: 268px;
  --topbar-h: 60px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--grey-900);
  background: var(--grey-100);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

a {
  color: var(--blue-600);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--white);
}

.login-hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
  background: linear-gradient(145deg, var(--blue-800) 0%, var(--blue-600) 55%, var(--blue-500) 100%);
  color: var(--white);
}

.login-hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-hero p {
  margin: 0;
  max-width: 28rem;
  line-height: 1.55;
  opacity: 0.92;
  font-size: 1.02rem;
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--grey-100);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.75rem;
  box-shadow: var(--shadow-lg);
  animation: fade-up 0.45s var(--ease);
}

.login-brand {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--blue-600);
}

.login-sub {
  margin: 0 0 1.5rem;
  color: var(--grey-600);
  font-size: 0.95rem;
}

/* Shell */
.admin-app {
  display: flex;
  min-height: 100vh;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 35;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}

body.sidebar-open .sidebar-backdrop {
  display: block;
  opacity: 1;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--blue-800);
  color: #e8eef8;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transform: translateX(0);
  transition: transform 0.28s var(--ease);
  box-shadow: var(--shadow-md);
}

.sidebar-brand {
  padding: 1.1rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}

.brand-name {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.72rem;
  opacity: 0.65;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.45rem 0.25rem;
  scrollbar-gutter: stable;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  color: #dce6f5;
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 2px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-icon {
  width: 1.35rem;
  text-align: center;
  font-size: 0.95rem;
  opacity: 0.92;
}

.sidebar-foot {
  padding: 0.65rem 0.75rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 0.25rem;
}

.sidebar-help {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef8;
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.sidebar-help:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-help kbd {
  float: right;
  font-size: 0.75rem;
  opacity: 0.85;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
  color: var(--white);
}

.sidebar-nav a.is-active {
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  font-weight: 600;
}

.sidebar-nav .nav-section {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  opacity: 0.55;
  padding: 0.85rem 0.75rem 0.3rem;
}

.admin-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title {
  font-weight: 600;
  font-size: 1.05rem;
  flex: 1;
  min-width: 0;
}

.topbar-search {
  flex: 0 1 280px;
}

.topbar-search input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--grey-200);
  border-radius: 8px;
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  position: relative;
  border: 0;
  background: transparent;
  padding: 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--grey-900);
}

.icon-btn:hover {
  background: var(--grey-100);
}

.badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--danger);
  color: var(--white);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-menu {
  position: relative;
}

.user-menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.user-menu summary::-webkit-details-marker {
  display: none;
}

.user-menu[open] summary {
  background: var(--grey-100);
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: 10px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 0.35rem;
  z-index: 50;
}

.user-menu-panel button,
.user-menu-panel a {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 0;
  background: none;
  border-radius: 6px;
  color: var(--grey-900);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.user-menu-panel button:hover,
.user-menu-panel a:hover {
  background: var(--grey-100);
}

.sidebar-toggle {
  display: none;
  border: 0;
  background: transparent;
  padding: 0.35rem;
  cursor: pointer;
}

.spa-body {
  background: var(--grey-100);
}

.admin-content {
  padding: 1.35rem 1.5rem 2rem;
  flex: 1;
  transition: opacity 0.12s var(--ease);
}

.admin-content.is-swapping {
  opacity: 0.55;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--blue-50);
  color: var(--blue-700);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.user-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  margin: 0.35rem 0.65rem !important;
  font-size: 0.8rem;
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--grey-700);
  margin: 4px 0;
  border-radius: 1px;
}

.welcome-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 1.1rem 1.25rem;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-lg);
}

.welcome-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 600;
}

.welcome-sub {
  margin: 0;
  color: var(--grey-600);
  max-width: 36rem;
  line-height: 1.45;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.quick-tile {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 0.95rem;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.quick-tile:hover {
  border-color: var(--blue-500);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.quick-tile-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.82rem;
  color: var(--grey-600);
}

.quick-tile-text strong {
  font-size: 0.92rem;
  color: var(--grey-900);
}

.quick-tile-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.grid-2-tight {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.75rem;
}

.shortcuts-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  max-width: 420px;
  margin: 10vh auto;
  box-shadow: var(--shadow-lg);
}

.shortcuts-modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.shortcuts-table {
  width: 100%;
  margin: 1rem 0;
  font-size: 0.9rem;
  border-collapse: collapse;
}

.shortcuts-table td {
  padding: 0.4rem 0;
  vertical-align: top;
}

.shortcuts-table td:first-child {
  width: 42%;
  color: var(--grey-700);
}

kbd {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  font-size: 0.78rem;
  border: 1px solid var(--grey-200);
  border-radius: 5px;
  background: var(--grey-100);
  font-family: inherit;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.page-intro {
  margin: -0.35rem 0 1rem;
  max-width: 40rem;
  line-height: 1.45;
}

.card {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  display: block;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: 12px;
  padding: 1rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s var(--ease);
}

.stat-card:hover {
  border-color: var(--blue-500);
  text-decoration: none;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--grey-600);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--blue-600);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.calc-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 960px) {
  .calc-grid {
    grid-template-columns: minmax(280px, 380px) 1fr;
    align-items: start;
  }
}

.calc-meta {
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
}

.calc-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 1rem;
}

.calc-dl dt {
  font-weight: 600;
  color: var(--grey-600);
}

.calc-dl dd {
  margin: 0;
}

.calc-highlight {
  font-size: 1.05rem;
  margin: 0.5rem 0;
}

.calc-section + .calc-section {
  margin-top: 1rem;
}

.size-block {
  border-top: 1px solid var(--grey-200);
  padding: 1.25rem 0;
}

.size-block:first-of-type {
  border-top: none;
  padding-top: 0;
}

.size-block-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.size-block-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.tier-heading {
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

.input-row input {
  flex: 1;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
}

label.field span {
  color: var(--grey-600);
  font-weight: 500;
}

input,
select,
textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-md);
  background: var(--white);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(31, 75, 153, 0.15);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn {
  transition: background 0.2s var(--ease), transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--blue-600);
  color: var(--white);
  box-shadow: 0 1px 2px rgba(31, 75, 153, 0.35);
}

.btn-primary:hover {
  background: var(--blue-700);
}

.btn-secondary:hover {
  background: var(--grey-100);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--white);
  border-color: var(--grey-200);
  color: var(--grey-900);
}

.btn-danger {
  background: var(--white);
  border-color: #fecdca;
  color: var(--danger);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--grey-200);
}

table.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--grey-600);
  background: var(--grey-100);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.data-table tr:hover td {
  background: #fafbfc;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pill-active {
  background: #ecfdf3;
  color: var(--success);
}

.pill-inactive,
.pill-draft {
  background: #fef3f2;
  color: var(--danger);
}

.pill-published {
  background: var(--blue-50);
  color: var(--blue-600);
}

.pill-warning {
  background: #fffaeb;
  color: #b54708;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filters label.field {
  min-width: 140px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--grey-600);
}

.empty-state,
.loading-state,
.error-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--grey-600);
}

.error-state {
  color: var(--danger);
}

.text-error {
  color: var(--danger);
  font-size: 0.88rem;
}

.text-muted {
  color: var(--grey-600);
  font-size: 0.88rem;
}

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--grey-200);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 0.85rem;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  color: var(--grey-600);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.is-active {
  color: var(--blue-600);
  border-bottom-color: var(--blue-600);
  font-weight: 600;
}

.toast-host {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  background: var(--grey-900);
  color: var(--white);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.2s ease;
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 29, 33, 0.45);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--white);
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  padding: 1.25rem;
  border: 1px solid var(--grey-200);
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

@media (max-width: 900px) {
  .login-page {
    grid-template-columns: 1fr;
  }

  .login-hero {
    display: none;
  }

  .login-panel {
    min-height: 100vh;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .admin-main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .topbar-search {
    display: none;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }
}
