:root {
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e6ea;
  --text: #1c2126;
  --text-muted: #5a6470;
  --accent: #1f5eff;
  --accent-hover: #1748c4;
  --accent-soft: #e8eeff;
  --danger: #d92d2d;
  --success: #1a8a4a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 24, 30, 0.08), 0 1px 2px rgba(20, 24, 30, 0.06);
}

[data-theme="dark"] {
  --bg: #14171c;
  --bg-soft: #1b1f26;
  --surface: #1b1f26;
  --border: #2a2f38;
  --text: #eef1f5;
  --text-muted: #9aa4b2;
  --accent: #5b8bff;
  --accent-hover: #7ea0ff;
  --accent-soft: #1e2740;
  --danger: #ff6b6b;
  --success: #45c98a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

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

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
}

.brand img {
  height: 34px;
  width: 34px;
}

.brand-tagline {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.main-nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
}

.main-nav a:hover {
  border-bottom-color: var(--accent);
}

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

/* Hamburger toggle (hidden on desktop) */

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  background: var(--text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

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

.nav-toggle.open span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-menu {
  display: none;
}

.theme-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.theme-toggle a {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.theme-toggle a.active {
  background: var(--accent);
  color: #fff;
}

/* Buttons */

.btn {
  display: inline-block;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
}

.btn-outline:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
}

.btn-danger:hover {
  background: #b32323;
  border-color: #b32323;
}

.btn-small {
  padding: 5px 12px;
  font-size: 12px;
}

/* Layout helpers */

.hero {
  padding: 56px 0 40px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.hero h1 {
  font-size: 32px;
  margin-bottom: 10px;
}

.hero p {
  color: var(--text-muted);
  max-width: 560px;
  margin: 0 auto 22px;
}

.hero-banner {
  max-width: 100%;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.section {
  padding: 40px 0;
}

.section h2 {
  margin-bottom: 20px;
  font-size: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card h3 {
  margin: 0;
  font-size: 16px;
}

.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.card .price {
  font-weight: 700;
  color: var(--accent);
  margin-top: auto;
}

.subject-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* Forms */

.form-box {
  max-width: 420px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.form-box h1 {
  font-size: 20px;
  margin-top: 0;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

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

.form-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  margin: 16px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.vk-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}

.vk-btn:hover {
  background: var(--accent-soft);
}

/* Flash messages */

.flashes {
  max-width: 1120px;
  margin: 16px auto 0;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.flash-success {
  border-color: var(--success);
  color: var(--success);
}

.flash-error {
  border-color: var(--danger);
  color: var(--danger);
}

.flash-info {
  color: var(--text-muted);
}

/* Tables (admin) */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

th {
  background: var(--bg-soft);
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
}

tr:last-child td {
  border-bottom: none;
}

.admin-shell {
  display: flex;
  min-height: calc(100vh - 62px);
}

.admin-sidebar {
  width: 220px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 18px 0;
  flex-shrink: 0;
}

.admin-sidebar a {
  display: block;
  padding: 9px 20px;
  color: var(--text);
  font-size: 14px;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.admin-main {
  flex: 1;
  padding: 26px 30px;
}

.admin-main h1 {
  margin-top: 0;
  font-size: 22px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card .num {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 13px;
}

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

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-on {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-off {
  background: var(--bg-soft);
  color: var(--text-muted);
}

/* Footer */

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 22px 0;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.material-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 720px;
  margin: 30px auto;
  box-shadow: var(--shadow);
}

.material-detail .price {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin: 14px 0;
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

/* ===========================================================
   Responsive: tablet and down
   =========================================================== */

@media (max-width: 860px) {
  .header-inner {
    flex-wrap: nowrap;
    padding: 12px 0;
  }

  .brand span {
    font-size: 16px;
  }

  .brand-tagline {
    display: none;
  }

  /* Hide the inline desktop nav + actions, show the hamburger instead */
  .main-nav,
  .header-actions {
    display: none;
  }

  .nav-toggle {
    display: flex;
    order: 3;
  }

  .brand {
    flex: 1;
    min-width: 0;
  }

  .brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Slide-down mobile menu */
  .mobile-menu {
    display: block;
    max-height: 0;
    overflow: hidden;
    border-top: 1px solid transparent;
    transition: max-height 0.25s ease;
    background: var(--surface);
  }

  .mobile-menu.open {
    max-height: 600px;
    border-top-color: var(--border);
  }

  .mobile-nav {
    display: flex;
    flex-direction: column;
    padding: 10px 20px 4px;
  }

  .mobile-nav a {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 500;
  }

  .mobile-nav a:last-child {
    border-bottom: none;
  }

  .mobile-theme-toggle {
    margin: 14px 20px;
    width: fit-content;
  }

  .mobile-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 20px 18px;
  }

  .mobile-actions .btn {
    width: 100%;
    text-align: center;
  }

  body.nav-open {
    overflow: hidden;
  }

  .hero {
    padding: 36px 0 28px;
  }

  .hero-banner {
    max-height: 180px;
    margin-bottom: 16px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .hero p {
    font-size: 14px;
  }

  .section {
    padding: 26px 0;
  }

  .section h2 {
    font-size: 19px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .card {
    padding: 14px;
  }

  .form-box {
    margin: 20px auto;
    padding: 20px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .material-detail {
    margin: 16px auto;
    padding: 18px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Admin: sidebar becomes a horizontal scroll strip above content */
  .admin-shell {
    flex-direction: column;
  }

  .admin-sidebar {
    width: 100%;
    display: flex;
    overflow-x: auto;
    padding: 10px 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
  }

  .admin-sidebar a {
    padding: 8px 14px;
    white-space: nowrap;
  }

  .admin-main {
    padding: 18px 16px;
  }

  .stat-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Tables scroll horizontally instead of squeezing columns */
  table {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: block;
  }

  tr {
    display: block;
    border-bottom: 8px solid var(--bg);
    padding: 10px 12px;
  }

  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
  }

  td:last-child {
    border-bottom: none;
  }

  td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
  }

  td[colspan] {
    display: block;
  }

  td[colspan]::before {
    content: none;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn,
  .form-actions .btn-outline {
    width: 100%;
    text-align: center;
  }
}

/* ===========================================================
   Responsive: small phones
   =========================================================== */

@media (max-width: 420px) {
  .container {
    padding: 0 14px;
  }

  .brand img {
    height: 28px;
    width: 28px;
  }

  .hero h1 {
    font-size: 21px;
  }

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

  .stat-cards {
    grid-template-columns: 1fr;
  }
}

/* ===========================================================
   Responsive: large desktop refinements
   =========================================================== */

@media (min-width: 1200px) {
  .container {
    max-width: 1200px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
}
