:root {
  --tg-blue: #0088cc;
  --tg-blue-dark: #006ba3;
  --tg-bg: #f4f4f5;
  --tg-card: #ffffff;
  --tg-text: #222222;
  --tg-muted: #707579;
  --tg-success: #4dcd5e;
  --tg-danger: #e53935;
  --tg-warning: #ffa726;
  --tg-border: #e1e3e6;
  --tg-hover: #f7f8fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  background: var(--tg-card);
  border: 1px solid var(--tg-border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.brand a {
  text-decoration: none;
  color: var(--tg-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.menu-toggle:hover {
  background: var(--tg-hover);
}

.menu-toggle svg {
  width: 22px;
  height: 22px;
  color: var(--tg-text);
}

.nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav a {
  text-decoration: none;
  color: var(--tg-text);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 15px;
}

.nav a:hover {
  background: rgba(0, 136, 204, 0.1);
  color: var(--tg-blue);
}

.user-area {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 16px;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.badge.success {
  background: rgba(77, 205, 94, 0.12);
  color: var(--tg-success);
}

.badge.danger {
  background: rgba(229, 57, 53, 0.12);
  color: var(--tg-danger);
}

.card {
  background: var(--tg-card);
  border: 1px solid var(--tg-border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  align-items: stretch;
}

.grid > * {
  display: flex;
  flex-direction: column;
}

.col-4 {
  grid-column: span 4;
}
.col-6 {
  grid-column: span 6;
}
.col-8 {
  grid-column: span 8;
}
.col-12 {
  grid-column: span 12;
}

h1,
h2,
h3 {
  margin: 0 0 8px 0;
  font-weight: 700;
}

h2 {
  font-size: 24px;
}
h3 {
  font-size: 18px;
}

.muted {
  color: var(--tg-muted);
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: var(--tg-blue);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
}

.btn:hover {
  background: var(--tg-blue-dark);
  transform: translateY(-1px);
}

.btn.light {
  background: var(--tg-hover);
  color: var(--tg-text);
}

.btn.light:hover {
  background: #e8eaed;
}

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

.table th,
.table td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--tg-border);
}

.table th {
  font-weight: 600;
  color: var(--tg-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--tg-hover);
}

.table tbody tr {
  transition: background 0.2s;
}

.table tbody tr:hover {
  background: var(--tg-hover);
}

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

.alert {
  padding: 14px 16px;
  border-radius: 10px;
  margin: 16px 0;
  font-size: 15px;
}

.alert.success {
  background: rgba(77, 205, 94, 0.12);
  color: var(--tg-success);
}

.alert.error {
  background: rgba(229, 57, 53, 0.12);
  color: var(--tg-danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--tg-card);
  border: 1px solid var(--tg-border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

.stat-card.blue {
  --color: var(--tg-blue);
}
.stat-card.success {
  --color: var(--tg-success);
}
.stat-card.warning {
  --color: var(--tg-warning);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  background: var(--color);
  color: white;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--tg-text);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: var(--tg-muted);
  font-weight: 500;
}

.chart-wrapper {
  position: relative;
  height: 300px;
  margin-top: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 10px;
}

.form-group {
  grid-column: span 6;
  margin-bottom: 16px;
}

.form-group.full {
  grid-column: span 12;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--tg-border);
  outline: none;
  background: #fff;
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--tg-blue);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.login-wrapper {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 18px;
}

.login-card {
  max-width: 420px;
  width: 100%;
  padding: 28px;
  border-radius: 16px;
  background: var(--tg-card);
  border: 1px solid var(--tg-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.login-card h2 {
  text-align: center;
  margin-bottom: 6px;
  font-size: 24px;
}

.login-card .muted {
  text-align: center;
  margin-bottom: 20px;
}

.input-with-icon {
  position: relative;
}

.input-with-icon input {
  padding-right: 42px;
}

.input-with-icon .pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-muted);
  border-radius: 6px;
  transition: background 0.2s;
}

.input-with-icon .pw-toggle:hover {
  background: var(--tg-hover);
}

.input-with-icon .pw-toggle:focus {
  outline: 2px solid rgba(0, 136, 204, 0.3);
}

.input-with-icon .pw-toggle svg {
  width: 20px;
  height: 20px;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .menu-toggle {
    display: inline-flex;
    position: absolute;
    right: 16px;
    top: 12px;
  }

  .nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 4px;
    margin-top: 12px;
  }

  .topbar.nav-open .nav {
    display: flex;
  }

  .nav a {
    width: 100%;
    padding: 10px 14px;
  }

  .user-area {
    width: 100%;
    order: -1;
  }

  .col-4,
  .col-6,
  .col-8 {
    grid-column: span 12;
  }

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

  .chart-wrapper {
    height: 250px;
  }
}

.small {
  font-size: 13px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.subject-card {
  grid-column: span 4;
  cursor: pointer;
  transition: transform 0.2s;
}

.subject-card:hover {
  transform: translateY(-2px);
}

.subject-card .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}

.subject-card .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.copy-input {
  position: absolute;
  left: -9999px;
}

@media (max-width: 1020px) {
  .subject-card {
    grid-column: span 6;
  }
}

@media (max-width: 640px) {
  .subject-card {
    grid-column: span 12;
  }

  .form-group {
    grid-column: span 12;
  }

  .container {
    padding: 12px;
  }

  .card {
    padding: 16px;
  }

  h2 {
    font-size: 20px;
  }
  h3 {
    font-size: 16px;
  }

  .stat-value {
    font-size: 28px;
  }

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