:root {
  color-scheme: light dark;
  --border: #d0d5dd;
  --accent: #2563eb;
  --danger: #dc2626;
  --bg-subtle: rgba(127, 127, 127, 0.08);
  --page-bg: #f8fafc;
  --surface: rgba(255, 255, 255, 0.9);
  --pattern-color: rgba(71, 85, 105, 0.14);
  --text: #1e293b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #0f172a;
    --surface: rgba(30, 41, 59, 0.88);
    --pattern-color: rgba(148, 163, 184, 0.16);
    --text: #e2e8f0;
    --border: #334155;
  }
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  line-height: 1.4;
  background-color: var(--page-bg);
  color: var(--text);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--pattern-color);
  -webkit-mask-image: url("/static/pattern.svg");
  mask-image: url("/static/pattern.svg");
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  -webkit-mask-size: 240px 240px;
  mask-size: 240px 240px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.nav a {
  text-decoration: none;
  color: inherit;
  opacity: 0.7;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  transition: background 0.15s ease, opacity 0.15s ease, color 0.15s ease;
}

.nav a:hover {
  opacity: 1;
  background: var(--bg-subtle);
}

.nav a.active {
  opacity: 1;
  color: var(--accent);
  background: rgba(37, 99, 235, 0.12);
}

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9em;
  opacity: 0.85;
}

.container {
  max-width: 960px;
  margin: 1.5rem auto;
  padding: 1.5rem 1.25rem 3rem;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.container-wide {
  max-width: min(1400px, 96vw);
}

h1 { margin-top: 0; }

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1.5rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

table.grid th, table.grid td {
  text-align: center;
  min-width: 90px;
}

.table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.table-scroll::-webkit-scrollbar {
  height: 9px;
}

.table-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

table.teacher-master-grid th, table.teacher-master-grid td {
  min-width: 44px;
  padding: 0.3rem 0.35rem;
  font-size: 0.85em;
}

table.teacher-master-grid .teacher-col {
  min-width: 160px;
  text-align: left;
  white-space: nowrap;
}

table.teacher-master-grid .lesson {
  font-size: 0.95em;
}

table.teacher-master-grid .meta {
  font-size: 0.85em;
}

.teachers-table tbody tr:nth-child(even),
.data-table tbody tr:nth-child(even) {
  background: rgba(127, 127, 127, 0.05);
}

.teachers-table tbody tr:hover,
.data-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.07);
}

.subject-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
  font-size: 0.85em;
}

.difficulty-form {
  margin: 0;
}

.difficulty-form select {
  width: 3.5rem;
  padding: 0.2rem 0.3rem;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  margin: 0;
}

.export-link {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  font-size: 0.9em;
  font-weight: 500;
  background: var(--bg-subtle);
}

.export-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-subtle);
  font-size: 0.85em;
  font-weight: 600;
  opacity: 0.8;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.toolbar-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  background: var(--bg-subtle);
}

.toolbar-panel h3 {
  margin: 0 0 0.6rem;
  font-size: 0.95em;
  opacity: 0.85;
}

.toolbar-panel .inline-form {
  margin-bottom: 0;
}

.toolbar-panel .hint {
  margin-bottom: 0;
}

.teacher-name {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.14);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85em;
}

td.actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  white-space: nowrap;
}

.btn-small {
  padding: 0.15rem 0.5rem;
  font-size: 0.8em;
}

.lesson { font-weight: 600; }
.meta { font-size: 0.8em; opacity: 0.75; }

.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
}

.stacked-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9em;
}

.stacked-form input {
  width: 100%;
  box-sizing: border-box;
}

.auth-layout {
  display: flex;
  gap: 3rem;
  align-items: center;
}

.auth-form-col {
  flex: 1 1 320px;
}

.auth-brand {
  flex: 1 1 320px;
  padding-left: 2rem;
  border-left: 1px solid var(--border);
}

.auth-brand h2 {
  margin: 0.75rem 0 0.5rem;
  font-size: 1.3em;
}

.auth-brand p {
  opacity: 0.85;
  margin-bottom: 0.75rem;
}

.auth-brand ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.9em;
  opacity: 0.85;
}

.auth-brand li {
  margin-bottom: 0.3rem;
}

@media (max-width: 700px) {
  .auth-layout {
    flex-direction: column;
    align-items: stretch;
  }

  .auth-brand {
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
  }
}

form.inline { display: inline; margin: 0; }

input, select, button {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: inherit;
}

.max-lessons-input {
  width: 6rem;
}

button {
  cursor: pointer;
  background: var(--bg-subtle);
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.danger {
  color: var(--danger);
}

.subtitle {
  opacity: 0.8;
  margin-top: -0.5rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.stat-card:hover {
  background: rgba(37, 99, 235, 0.09);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.stat-icon {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1;
}

.stat-label {
  font-size: 0.85rem;
  opacity: 0.75;
}

.hero-actions {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.hero-actions form {
  margin: 0;
}

button.primary.large {
  padding: 0.7rem 1.5rem;
  font-size: 1.05rem;
}

.secondary-link {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.secondary-link:hover {
  text-decoration: underline;
}

.form-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.cancel-link {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  border: 1px solid transparent;
  color: inherit;
  opacity: 0.7;
  text-decoration: none;
  font-weight: 500;
}

.cancel-link:hover {
  opacity: 1;
  border-color: var(--border);
  background: var(--bg-subtle);
}

.hint {
  font-size: 0.85em;
  opacity: 0.75;
  margin-top: 0.4rem;
  margin-bottom: 0.75rem;
}

.flash {
  border: 1px solid var(--accent);
  background: rgba(37, 99, 235, 0.1);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.25rem;
}

.flash p { margin: 0.2rem 0; }

.warning {
  border: 1px solid #d97706;
  background: rgba(217, 119, 6, 0.1);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.section-title {
  margin: 2rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.section-title:first-of-type {
  margin-top: 0;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.55rem 1rem;
  text-decoration: none;
  color: inherit;
  opacity: 0.65;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  opacity: 1;
}

.tab.active {
  opacity: 1;
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.schedule-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.25rem;
  background: var(--bg-subtle);
  margin-bottom: 1.25rem;
}

.schedule-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1em;
}

.schedule-card table {
  margin-bottom: 0;
  background: var(--surface);
}

.empty-state {
  opacity: 0.75;
  padding: 1.5rem 0;
  text-align: center;
}
