:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e7e9f1;
  --text: #16192a;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #fde047;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 28px rgba(16, 24, 40, .10);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
}

a, button, .btn, input, select, td.slot-cell {
  transition: background-color .16s ease, color .16s ease, border-color .16s ease,
              box-shadow .16s ease, transform .12s ease, opacity .16s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ===== Bo khung cong: sidebar trai + noi dung phai ===== */
.shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.brand-title { font-weight: 700; font-size: 14px; line-height: 1.3; }
.brand-sub { font-size: 11px; color: var(--muted); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
}

.sidebar-nav .group-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
  padding: 14px 10px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, padding-left .15s ease;
}

.sidebar-nav a:hover { background: #f0f2f8; padding-left: 15px; }

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .75;
}
.sidebar-nav a.active .nav-icon, .sidebar-nav a:hover .nav-icon { opacity: 1; }
.nav-icon.fb-icon { fill: currentColor; stroke: none; }
.sidebar-nav a.active {
  background: #e8f0ff; color: var(--primary-dark); font-weight: 600;
  border-left-color: var(--primary-dark);
}

/* Muc nav co submenu xo xuong (vd Xem toan truong) */
.nav-group summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  cursor: pointer;
  list-style: none;
  transition: background-color .15s ease, color .15s ease;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::marker { content: ""; }
.nav-group summary:hover { background: #f0f2f8; }
.nav-group summary.active {
  background: #e8f0ff; color: var(--primary-dark); font-weight: 600;
  border-left-color: var(--primary-dark);
}
.nav-group summary span { flex: 1; }
.nav-chevron {
  width: 14px; height: 14px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .18s ease;
}
.nav-group[open] summary .nav-chevron { transform: rotate(180deg); }
.nav-submenu { display: flex; flex-direction: column; padding: 2px 0 4px 34px; }
.nav-submenu a {
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 1px;
  transition: background-color .15s ease, color .15s ease;
}
.nav-submenu a:hover { background: #f0f2f8; color: var(--text); }
.nav-submenu a.active { color: var(--primary-dark); font-weight: 600; background: #eef3ff; }

.sidebar-widget {
  margin: 10px 14px 16px;
  padding: 14px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f0f4ff, #f7fafe);
  border: 1px solid var(--border);
}
.sidebar-widget-weekday { font-size: 13px; font-weight: 600; color: var(--primary-dark); }
.sidebar-widget-day { font-size: 12px; color: var(--muted); margin-top: 1px; }
.sidebar-widget-facts {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(37, 99, 235, .12);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-widget-facts b { color: var(--text); font-size: 14px; margin-right: 3px; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  transition: transform .18s ease;
}
.avatar:hover { transform: scale(1.08); }
.avatar.guest { background: #9ca3af; }

.sidebar-user-info { font-size: 13px; line-height: 1.4; overflow: hidden; }
.sidebar-user-name { font-weight: 600; }
.sidebar-user-info a { color: var(--primary); text-decoration: none; font-size: 12px; }
.sidebar-user-info a:hover { text-decoration: underline; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.page-body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
  flex: 1;
  animation: fadeInUp .35s ease;
}

.page-body.wide {
  max-width: none;
  padding: 14px 18px;
}

.app-footer {
  padding: 14px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px;
    gap: 4px;
  }
  .sidebar-nav .group-label { display: none; }
  .sidebar-nav a {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 7px 12px;
    margin-bottom: 0;
    border-left: none;
  }
  .sidebar-nav a.active { border-left: none; border-bottom: 2px solid var(--primary-dark); }
  .sidebar-widget { display: none; }
  .sidebar-user { border-top: 1px solid var(--border); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
  animation: fadeIn .3s ease;
}
.card:hover { box-shadow: var(--shadow-md); }

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 10px; }
p.muted, .muted { color: var(--muted); font-size: 13px; }

.welcome-banner {
  background:
    linear-gradient(120deg, rgba(9,16,34,.94), rgba(20,35,72,.88) 55%, rgba(28,51,96,.80)),
    url("img/banner-bg.jpg");
  background-size: cover;
  background-position: center 30%;
  border-radius: 14px;
  padding: 30px 32px;
  margin-bottom: 16px;
  animation: fadeInUp .45s ease;
  position: relative;
  overflow: hidden;
}
.welcome-banner::after {
  content: "";
  position: absolute;
  top: -60px; right: -60px;
  width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(255,255,255,.08), transparent 70%);
  border-radius: 50%;
}
.welcome-banner h1 { margin: 0 0 6px; font-size: 21px; font-weight: 600; color: #fff; letter-spacing: .01em; }
.welcome-banner p { margin: 0; color: #b9c6e6; font-size: 13.5px; }

.stat-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.stat {
  flex: 1;
  min-width: 130px;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
  animation: fadeInUp .4s ease backwards;
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat:nth-child(1) { animation-delay: .02s; }
.stat:nth-child(2) { animation-delay: .07s; border-top-color: #16a34a; }
.stat:nth-child(3) { animation-delay: .12s; border-top-color: #2563eb; }
.stat:nth-child(4) { animation-delay: .17s; border-top-color: #dc2626; }
.stat:nth-child(5) { animation-delay: .22s; border-top-color: #d97706; }
.stat .n {
  font-size: 26px; font-weight: 700;
  transition: color .2s ease;
}
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
th {
  background: #f7f8fc;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-top: 1px solid var(--border);
}
table:not(.grid) tbody tr, table:not(.grid) tr:not(:first-child) {
  transition: background-color .12s ease;
}
table:not(.grid) tr:hover td { background: #f7f9fd; }

table.grid { table-layout: fixed; }
table.grid th, table.grid td { border: 1px solid var(--border); text-align: center; vertical-align: middle; }
table.grid td.slot-cell { height: 56px; }
table.grid .subj { font-weight: 700; font-size: 1.05em; }
table.grid .teacher { color: var(--muted); }

/* Sang / chieu 2 mau khac nhau de de phan biet */
table.grid th.morning, table.grid td.morning { background: #e8f0ff; }
table.grid th.afternoon, table.grid td.afternoon { background: #fff3df; }
table.grid td.off { background: #eee; color: var(--muted); }

/* Bang gop toan truong: table-layout auto de cot tu gian theo noi dung,
   tranh vo chu giua tu; o rong hon han, dong/cot dau dinh khi cuon */
table.grid.all-tkb { font-size: 11px; table-layout: auto; width: 100%; }
table.grid.all-tkb th, table.grid.all-tkb td { padding: 3px 2px; white-space: nowrap; }
table.grid.all-tkb td.slot-cell.small { height: 36px; min-width: 44px; padding: 2px 3px; white-space: nowrap; }
table.grid.all-tkb .subj { display: block; font-size: 11px; }
table.grid.all-tkb .teacher { display: block; font-size: 9px; white-space: nowrap; }
table.grid.all-tkb th:first-child, table.grid.all-tkb td:first-child {
  position: sticky; left: 0; background: white; z-index: 2; min-width: 46px;
}
table.grid.all-tkb tr:nth-child(2) th {
  position: sticky; top: 0; background: #f0f2f8; z-index: 3;
}
table.grid.all-tkb tr:nth-child(2) th:first-child {
  z-index: 4;
}

/* Bang theo tung lop (3 cot khoi): chu to hon vua phai */
.khoi-columns { display: flex; gap: 14px; align-items: flex-start; }
.khoi-col { flex: 1; min-width: 0; }
.khoi-col > h2 { position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 1; }
table.small-tkb { font-size: 13px; }
table.small-tkb th, table.small-tkb td { padding: 5px 6px; }
table.small-tkb td.slot-cell { height: 40px; min-width: 46px; }
table.small-tkb .subj { display: block; font-size: 13px; }
table.small-tkb .teacher { display: block; font-size: 11px; }
@media (max-width: 900px) {
  .khoi-columns { flex-direction: column; }
}

/* Panel sua truc tiep tren bang gop toan truong */
.combined-wrap { display: flex; gap: 12px; align-items: flex-start; }
.combined-wrap .table-scroll { flex: 1; min-width: 0; overflow-x: auto; }
.side-panel {
  flex: 0 0 300px;
  width: 300px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  position: sticky;
  top: 12px;
  max-height: 90vh;
  overflow-y: auto;
}
.side-panel.closed { display: none; }
.panel-head { margin-bottom: 10px; font-size: 14px; }
.panel-close {
  float: right; border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--muted);
}
td.slot-cell.editable { cursor: pointer; }
td.slot-cell.editable:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
table.grid td.off { background: #f4f4f4; color: var(--muted); }
table.grid .subj { font-weight: 600; }
table.grid .teacher { font-size: 11px; color: var(--muted); display: block; }
table.grid a { color: inherit; text-decoration: none; display: block; }
table.grid a:hover { background: #eef2ff; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.mandatory { background: #fef3c7; color: #92400e; }
.badge.open { background: #dbeafe; color: #1e40af; }
.badge.manual { background: #ede9fe; color: #5b21b6; }
.badge.missing { background: #fee2e2; color: #991b1b; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease, transform .12s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(37,99,235,.25); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn.secondary { background: #eef0f5; color: var(--text); }
.btn.secondary:hover { background: #e4e7ef; box-shadow: 0 4px 10px rgba(0,0,0,.06); }
.btn.secondary:hover { background: #d1d5db; }

select, input[type=text], input[type=password] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

input[type=file] {
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
  max-width: 190px;
}
input[type=file]::file-selector-button {
  padding: 7px 14px;
  margin-right: 10px;
  border: none;
  border-radius: 7px;
  background: #eef0f5;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .15s ease;
}
input[type=file]::file-selector-button:hover { background: #e4e7ef; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }

.warning-list li { margin-bottom: 4px; font-size: 13px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 860px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

.class-links, .teacher-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.class-links a, .teacher-links a {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  background: white;
}
.class-links a:hover, .teacher-links a:hover { border-color: var(--primary); color: var(--primary); }

.class-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.class-col { display: flex; flex-direction: column; gap: 6px; }
.pill {
  display: block;
  text-align: center;
  border-radius: 7px;
  padding: 6px 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: transform .12s ease, box-shadow .12s ease;
}
.pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.pill.khoi10 { background: #eaf2ff; color: #1d4ed8; border-color: #cfe0ff; }
.pill.khoi11 { background: #fef8e3; color: #92730c; border-color: #f6e6ab; }
.pill.khoi12 { background: #fdeaea; color: #b42323; border-color: #f6c9c9; }
@media (max-width: 560px) {
  .class-cols { grid-template-columns: 1fr; }
}

.news-item {
  display: flex;
  gap: 12px;
  padding: 10px 6px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background-color .12s ease;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: #f7f9fd; }
.news-item img { width: 84px; height: 62px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.news-title { font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.news-summary { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

.announcement-card .announcement-img {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 10px auto 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.contact-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.contact-list li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.contact-list .nav-icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--primary); opacity: 1; }
.contact-list a { color: var(--text); text-decoration: none; }
.contact-list a:hover { color: var(--primary); text-decoration: underline; }

fieldset { border: none; padding: 0; margin: 0 0 16px; }
legend { font-weight: 600; margin-bottom: 6px; }

.checkbox-grid td { cursor: pointer; }
.checkbox-grid input[type=checkbox] { width: 18px; height: 18px; }

/* ===== Trang dang nhap rieng (khong co sidebar) ===== */
body.login-page {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.login-shell { display: flex; min-height: 100vh; }
.login-visual {
  flex: 1.15;
  background-size: cover;
  background-position: center;
  position: relative;
  display: flex;
  align-items: flex-end;
  animation: fadeIn .5s ease;
}
.login-visual-overlay {
  width: 100%;
  padding: 48px;
  color: white;
  background: linear-gradient(180deg, rgba(10,20,40,0) 0%, rgba(10,20,45,.82) 100%);
  animation: fadeInUp .5s ease .1s backwards;
}
.login-visual-overlay h2 { margin: 10px 0 2px; font-size: 26px; }
.login-visual-overlay p { margin: 0; opacity: .9; font-size: 14px; }
.login-logo {
  width: 68px; height: 68px; border-radius: 14px; object-fit: cover;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.login-form-side {
  flex: 0 0 440px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 340px; animation: fadeInUp .45s ease .05s backwards; }
.login-card-logo { width: 58px; height: 58px; border-radius: 12px; object-fit: cover; margin-bottom: 16px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card form label { font-size: 13px; font-weight: 600; margin-top: 14px; display: block; }
.login-card input { width: 100%; margin-top: 5px; padding: 10px 12px; }
@media (max-width: 760px) {
  .login-visual { display: none; }
  .login-form-side { flex: 1; }
}
