:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --line: #d7dee8;
  --text: #2f3a4b;
  --muted: #6f7a88;
  --primary: #007bff;
  --primary-dark: #005ec2;
  --secondary: #17a2b8;
  --sidebar: #2b3544;
  --sidebar-hover: #354254;
  --sidebar-active: #3f4f65;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --radius: 10px;
  --shadow: 0 10px 24px rgba(27, 39, 54, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
}

h1,
h2,
h3,
h4,
h5 {
  margin: 0;
  font-family: "Montserrat", "Trebuchet MS", sans-serif;
}

h5 {
  margin-bottom: 8px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #dce6f4 0%, #f4f6f9 45%, #ebf4ff 100%);
}

.login-card {
  width: min(460px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.eyebrow {
  font-size: 12px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  margin-bottom: 4px;
}

.muted {
  color: var(--muted);
}

#login-error {
  margin: 0;
  min-height: 18px;
  color: var(--danger);
  font-size: 0.9rem;
}

.dashboard-layout {
  --sidebar-width: 260px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 220ms ease;
}

.dashboard-layout.collapsed {
  --sidebar-width: 80px;
}

.sidebar {
  background: var(--sidebar);
  color: #e9eef4;
  padding: 18px 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-brand h2 {
  font-size: 18px;
  color: #ffffff;
}

.sidebar-brand small {
  color: #b7c2d3;
}

.sidebar-nav {
  overflow-y: auto;
  padding-right: 2px;
}

.nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9cacc3;
  margin: 14px 8px 8px;
  font-weight: 700;
}

.nav-link {
  width: 100%;
  border: 0;
  border-radius: 8px;
  margin-bottom: 6px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  color: #deebfd;
  font-weight: 600;
  cursor: pointer;
}

.nav-link:hover {
  background: var(--sidebar-hover);
}

.nav-link.active {
  background: var(--sidebar-active);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.nav-icon {
  width: 18px;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  white-space: nowrap;
}

.content-area {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.content-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 16px 20px;
}

.content-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content-header h3 {
  font-size: 22px;
  margin-bottom: 4px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.view-stack {
  padding: 18px;
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.stacked-form {
  display: grid;
  gap: 10px;
}

.stacked-form label,
.mini-form label,
.compact-label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.92rem;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}

.readonly-field {
  color: #617287;
}

.stacked-form input[readonly],
.stacked-form textarea[readonly],
.stacked-form select[readonly],
.readonly-field input[readonly] {
  background: #eef4fb;
  border-color: #c4d4e6;
  color: #42586e;
}

.stacked-form input[readonly]:focus,
.stacked-form textarea[readonly]:focus,
.stacked-form select[readonly]:focus,
.readonly-field input[readonly]:focus {
  outline: none;
  border-color: #c4d4e6;
}

.stacked-form label:has(input[readonly]),
.stacked-form label:has(textarea[readonly]),
.stacked-form label:has(select[readonly]) {
  color: #5e7288;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.radio-option input[type="radio"] {
  width: auto;
  margin: 0;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(0, 123, 255, 0.2);
  border-color: var(--primary);
}

.btn {
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(120deg, var(--primary), var(--primary-dark));
  color: #fff;
}

.btn-secondary {
  background: #edf6ff;
  border: 1px solid #b9d8ff;
  color: #1a4a8a;
}

.btn-small {
  background: var(--secondary);
  color: #fff;
  padding: 7px 11px;
  font-size: 0.85rem;
}

.btn-logout {
  background: var(--danger);
  color: #fff;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-logout .nav-icon svg {
  stroke: #fff;
}

.dashboard-layout.collapsed .sidebar-brand h2,
.dashboard-layout.collapsed .sidebar-brand small,
.dashboard-layout.collapsed .nav-group,
.dashboard-layout.collapsed .nav-label {
  display: none;
}

.dashboard-layout.collapsed .sidebar-brand {
  padding: 10px;
  min-height: 44px;
}

.dashboard-layout.collapsed .nav-link,
.dashboard-layout.collapsed .btn-logout {
  justify-content: center;
  padding-left: 10px;
  padding-right: 10px;
}

.inline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.inline-header.wrap {
  flex-wrap: wrap;
}

.filter-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 10px;
  background: rgba(0, 123, 255, 0.1);
  color: var(--primary);
  font-weight: 700;
}

.firebase-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
}

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

.split-view {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  cursor: pointer;
}

.list-item.active {
  border-color: var(--primary);
  background: rgba(0, 123, 255, 0.08);
}

.list-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-copy {
  min-width: 0;
}

.item-copy small {
  white-space: normal;
}

.tiny-btn {
  border: 1px solid #d6e6ff;
  background: #eef5ff;
  color: #2456a5;
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tiny-btn.active {
  background: #fff5db;
  border-color: #ffd573;
  color: #8a6300;
}

.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 700;
}

.badge-success {
  background: #e4f7ea;
  color: #1b7c3a;
}

.badge-muted {
  background: #f0f3f7;
  color: #6a7889;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 48vh;
  overflow: auto;
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  font-size: 0.92rem;
  vertical-align: middle;
}

th {
  background: #eef3f8;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.row-btn.trend {
  border-color: #ffd573;
  background: #fff8e5;
  color: #8a6300;
}

.row-btn.link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.row-btn.link:hover {
  text-decoration: underline;
}

.mini-form {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

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

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

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-box {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f9fbff;
  min-height: 140px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.preview-box.small {
  min-height: 90px;
}

.preview-image {
  max-width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: none;
}

.rich-editor {
  display: grid;
  gap: 8px;
}

.rich-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.rich-surface {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  overflow: auto;
}

.rich-surface:focus {
  outline: 2px solid rgba(0, 123, 255, 0.2);
  border-color: var(--primary);
}

.autocomplete-cell {
  position: relative;
  display: grid;
  gap: 6px;
}

.autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  display: none;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 6px;
}

.autocomplete-list.open {
  display: grid;
  gap: 4px;
}

.autocomplete-option {
  border: 0;
  background: #fff;
  text-align: left;
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
}

.autocomplete-option:hover {
  background: #eef5ff;
}

.autocomplete-option small {
  display: block;
  color: #6a7889;
}

.preview-image.has-image {
  display: block;
}

.quick-links-layout {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  align-items: start;
}

.quick-links-layout > .card:first-child {
  padding: 12px;
}

.quick-links-layout #quick-links-list {
  max-height: 54vh;
  gap: 6px;
}

.quick-links-layout #quick-links-list .list-item {
  padding: 8px 9px;
}

.quick-links-layout #quick-links-list .list-item strong {
  display: block;
  font-size: 0.95rem;
  line-height: 1.3;
}

.quick-links-layout #quick-links-list .list-item small {
  margin-top: 2px;
  font-size: 0.82rem;
  line-height: 1.3;
  word-break: break-word;
}

.quick-links-layout #quick-links-form {
  min-width: 0;
}

.compact {
  align-content: start;
}

.config-form {
  width: min(780px, 100%);
}

@media (max-width: 1150px) {
  .firebase-layout,
  .split-view,
  .quick-links-layout {
    grid-template-columns: 1fr;
  }

  .two-col,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 320px;
  }

  .list {
    max-height: 280px;
  }
}

@media (max-width: 980px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 10px;
  }

  .sidebar-nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 8px;
  }

  .nav-group {
    display: none;
  }

  .nav-link {
    min-width: max-content;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .dashboard-layout.collapsed .sidebar-brand h2,
  .dashboard-layout.collapsed .sidebar-brand small,
  .dashboard-layout.collapsed .nav-label {
    display: inline;
  }

  .dashboard-layout.collapsed .nav-group {
    display: none;
  }

  .dashboard-layout.collapsed .nav-link,
  .dashboard-layout.collapsed .btn-logout {
    justify-content: flex-start;
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 720px) {
  .content-header,
  .view-stack {
    padding: 12px;
  }

  .content-header h3 {
    font-size: 18px;
  }

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

  .login-card {
    padding: 20px;
  }
}
