:root {
  --df-black: #111111;
  --df-white: #ffffff;
  --df-yellow: #ffc107;
  --df-yellow-soft: #ffe082;
  --df-gray: #efefef;
  --df-border: #d8d8d8;
  --df-danger: #d7263d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--df-black);
  background: radial-gradient(circle at top left, #fff8dd, #f7f7f7 35%, #f0f0f0);
}

.topbar {
  background: linear-gradient(90deg, var(--df-black), #232323);
  color: var(--df-white);
  padding: 14px 24px;
  border-bottom: 4px solid var(--df-yellow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--df-yellow);
  color: var(--df-black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
}

.brand-title {
  margin: 0;
  font-weight: 700;
}

.brand-subtitle {
  margin: 0;
  font-size: 13px;
  color: #d8d8d8;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.user-menu a {
  color: var(--df-yellow);
  font-weight: 700;
  text-decoration: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-shell {
  width: min(420px, calc(100% - 32px));
}

.login-panel {
  background: var(--df-white);
  border: 1px solid var(--df-border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.login-panel .logo {
  margin-bottom: 14px;
}

.login-panel h1 {
  margin: 0 0 16px;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 84px);
  transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 72px 1fr;
}

.sidebar {
  background: var(--df-black);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 10px;
  border-color: #3a3a3a;
  background: #222222;
  color: var(--df-yellow);
}

.toggle-icon {
  font-size: 22px;
  line-height: 1;
}

.sidebar a {
  text-decoration: none;
  color: #dddddd;
  padding: 10px 12px;
  border-radius: 10px;
  transition: 0.2s ease;
}

.sidebar a:hover,
.sidebar a.active {
  background: var(--df-yellow);
  color: var(--df-black);
  font-weight: 600;
}

.sidebar-collapsed .sidebar {
  align-items: center;
}

.sidebar-collapsed .sidebar a,
.sidebar-collapsed .sidebar-toggle {
  width: 48px;
  min-height: 44px;
  padding: 10px 6px;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-collapsed .sidebar a {
  text-align: center;
  font-size: 0;
}

.sidebar-collapsed .sidebar a::first-letter {
  font-size: 16px;
}

.sidebar-collapsed .toggle-text {
  display: none;
}

.content {
  padding: 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
}

.cards-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.cards-grid.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  background: var(--df-white);
  border: 1px solid var(--df-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  min-width: 0;
}

.card h2,
.card h3 {
  margin-top: 0;
}

.card.stat {
  border-left: 6px solid var(--df-yellow);
}

.card.stat p {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
}

form {
  display: grid;
  gap: 8px;
}

input,
select,
textarea,
button {
  width: 100%;
  border: 1px solid var(--df-border);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--df-yellow-soft);
  border-color: var(--df-yellow);
}

button {
  background: var(--df-yellow);
  border-color: #e0a800;
  color: var(--df-black);
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.97);
}

button.danger {
  background: #fff0f2;
  border-color: #ffc8cf;
  color: var(--df-danger);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  width: 100%;
  border: 1px solid #e0a800;
  border-radius: 8px;
  padding: 10px;
  background: var(--df-yellow);
  color: var(--df-black);
  font-weight: 700;
  text-decoration: none;
}

.modal-actions a,
td a[href*="edit_"],
td a[href*="edit_id"],
td a[href*="mode=student"],
td a[href*="mode=contacts"],
td a[href*="edit_contact_id"],
td a[href*="page=students"][href*="edit_id"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  width: auto;
  border: 1px solid #d9dde3;
  border-radius: 8px;
  padding: 7px 10px;
  background: #ffffff;
  color: #2b2b2b;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-actions a {
  min-height: 42px;
  background: #f7f7f7;
}

.modal-actions .button-link {
  border-color: #e0a800;
  background: var(--df-yellow);
  color: var(--df-black);
}

.modal-actions a:hover,
td a[href*="edit_"]:hover,
td a[href*="edit_id"]:hover,
td a[href*="mode=student"]:hover,
td a[href*="mode=contacts"]:hover,
td a[href*="edit_contact_id"]:hover {
  border-color: var(--df-yellow);
  background: #fff8dd;
  color: var(--df-black);
}

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

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

th {
  background: #fafafa;
}

.tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.tag.ok {
  background: #ecfff1;
  color: #1c7a3d;
}

.tag.warn {
  background: #fff9e6;
  color: #9a6b00;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-form {
  display: inline-block;
  width: auto;
  margin-left: 6px;
}

.inline-form button {
  min-height: 34px;
  width: auto;
  padding: 7px 10px;
  font-size: 13px;
}

.card a {
  color: #8a6400;
  font-weight: 600;
}

.card td a[href*="edit_"],
.card td a[href*="edit_id"],
.card td a[href*="mode=student"],
.card td a[href*="mode=contacts"],
.card td a[href*="edit_contact_id"],
.card td a[href*="page=students"][href*="edit_id"] {
  color: #2b2b2b;
}

.table-filter {
  margin: 10px 0 12px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border-radius: 14px;
  padding: 18px;
  border: 1px solid var(--df-border);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.25);
  position: relative;
}

.modal-card.wide {
  width: min(1040px, 100%);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin: -4px -4px 8px 12px;
  border: 1px solid var(--df-border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--df-black);
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 2;
}

.modal-close:hover {
  border-color: var(--df-yellow);
  background: #fff8dd;
}

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

.details-grid div {
  border: 1px solid var(--df-border);
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
}

.details-grid dt {
  margin-bottom: 4px;
  color: #666666;
  font-size: 12px;
  font-weight: 700;
}

.details-grid dd {
  margin: 0;
  font-size: 14px;
}

.alert {
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-weight: 600;
}

.alert.success {
  background: #e8fff0;
  border: 1px solid #bae8c8;
  color: #21663a;
}

.alert.error {
  background: #fff1f3;
  border: 1px solid #f6c5cc;
  color: #8f1d2c;
}

.report-filter {
  width: 360px;
}

.checkbox-group {
  border: 1px solid var(--df-border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.checkbox-group legend {
  font-weight: 700;
  padding: 0 6px;
}

.checkbox-group label,
label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input[type="checkbox"],
label input[type="checkbox"] {
  width: auto;
}

@media (max-width: 1100px) {
  .cards-grid,
  .cards-grid.two-col,
  .cards-grid.three-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }

  .sidebar a {
    width: 48%;
    text-align: center;
  }

  .sidebar-toggle {
    width: 100%;
  }

  .sidebar-collapsed .sidebar a {
    display: none;
  }

  .sidebar-collapsed .sidebar-toggle {
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .content {
    padding: 16px;
  }

  .details-grid,
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
