/* ZERDELI LAB — ортақ панель стилі (әкімші, мұғалім, оқушы)
   Қозғалыс ережелері Emil Kowalski «emil-design-eng» скиліне сүйенеді (MIT):
   - тек transform және opacity анимацияланады, `transition: all` жоқ;
   - кіру/шығу — ease-out, экрандағы қозғалыс — ease-in-out, ease-in ешқашан;
   - UI анимациясы 300 мс-тан аспайды (модаль, drawer, toast — ерекшелік);
   - шығу кіруден жылдам; жиі қолданылатын әрекеттер анимациясыз;
   - hover тек тінтуірі бар құрылғыда; reduced-motion кезінде тек opacity қалады. */
:root {
  /* Бренд — бұрынғы жасыл-ақ палитра */
  --brand: #075b3b;
  --brand-2: #12834d;
  --brand-hover: #0a6a45;
  --brand-soft: #e5f4ea;
  --brand-tint: #f2f9f4;
  --ink: #15372a;
  --muted: #5b7166;
  --line: #dde9e1;
  --line-strong: #c4d9cb;
  --paper: #fff;
  --bg: #f4f7f5;
  --red: #c2414f;
  --red-soft: #fbe9eb;
  --amber: #a86d12;
  --amber-soft: #fdf3e1;

  /* Көлеңкелер: жартылай мөлдір, қабатты */
  --shadow-xs: 0 1px 2px rgb(16 46 32 / .06);
  --shadow: 0 1px 2px rgb(16 46 32 / .04), 0 4px 16px -6px rgb(16 46 32 / .10);
  --shadow-lift: 0 2px 4px rgb(16 46 32 / .05), 0 10px 28px -8px rgb(16 46 32 / .16);
  --shadow-pop: 0 0 0 1px rgb(16 46 32 / .06), 0 4px 8px -4px rgb(16 46 32 / .10), 0 18px 44px -12px rgb(16 46 32 / .28);
  --ring: 0 0 0 3px rgb(18 131 77 / .22);

  --radius: 16px;
  --radius-sm: 10px;

  /* Қисықтар (emil-design-eng) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Segoe UI", Inter, system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
}
::selection { background: #bfe6cc; color: var(--ink); }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: var(--brand-2); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num, .stat-value, td, .mono { font-variant-numeric: tabular-nums; }

/* Layout */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 260px; color: #fff;
  background: linear-gradient(180deg, #08603e 0%, var(--brand) 40%, #064e33 100%);
  padding: 22px 14px; display: flex; flex-direction: column; z-index: 20; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #ffffff33 transparent;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 12px; background: #ffffff1f; display: grid; place-items: center; font-weight: 900;
  box-shadow: inset 0 0 0 1px #ffffff26, inset 0 1px 0 #ffffff33;
}
.brand small { display: block; font-weight: 600; font-size: 12px; letter-spacing: .08em; opacity: .75; text-transform: uppercase; }
.nav-label { font-size: 12px; letter-spacing: .12em; opacity: .6; padding: 10px 10px 6px; }
.navbtn {
  position: relative; width: 100%; min-height: 42px; border: 0; background: transparent; color: #d3eadc; border-radius: 10px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px; text-align: left; font-weight: 600; margin: 2px 0;
  transition: background-color 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.navbtn:active { transform: scale(0.98); }
.navbtn.active { background: #ffffff1f; color: #fff; box-shadow: inset 0 0 0 1px #ffffff14; }
.navbtn.active::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: #9ee6b8;
}
.navbtn .ico { width: 20px; flex-shrink: 0; text-align: center; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid #ffffff14; }
.sidebar-scrim { display: none; }
.main { margin-left: 260px; flex: 1; min-width: 0; padding: 0 28px 40px; }
.topbar {
  position: sticky; top: 0; z-index: 15; height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 -28px 24px; padding: 0 28px; border-bottom: 1px solid var(--line);
  background: rgb(244 247 245 / .86); -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
}
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.centre-picker { display: flex; align-items: center; gap: 8px; margin-left: auto; font-weight: 700; font-size: 14px; color: var(--muted); }
.centre-picker .input { width: auto; min-width: 150px; min-height: 40px; padding: 6px 12px; font-weight: 700; color: var(--brand); }
.whoami { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.whoami .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 14px; text-transform: uppercase;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line);
}
.role-chip { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.btn.menu-toggle { display: none; }

/* Cards & grid */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 18px; margin: 0 0 6px; letter-spacing: -0.01em; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
button.card {
  width: 100%; font: inherit; color: inherit; display: block;
  transition: border-color 150ms ease, box-shadow 200ms ease, transform 160ms var(--ease-out);
}
button.card:active { transform: scale(0.98); }
.stat-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; line-height: 1.2; }
.section { display: none; }
.section.active { display: block; }
.stack > * + * { margin-top: 16px; }

/* Buttons */
.btn {
  min-height: 40px; border: 1px solid var(--line-strong); background: #fff; border-radius: var(--radius-sm); padding: 8px 16px;
  font-weight: 700; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  box-shadow: var(--shadow-xs); user-select: none; -webkit-user-select: none;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease;
}
a.btn { text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 1px 2px rgb(7 91 59 / .35), inset 0 1px 0 rgb(255 255 255 / .14);
}
.btn.danger { color: var(--red); border-color: #efc5ca; }
.btn.small { min-height: 32px; padding: 5px 11px; font-size: 14px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; }
.btn.primary .spinner { border-color: #ffffff4d; border-top-color: #fff; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.input, select.input, textarea.input {
  min-height: 42px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 12px; background: #fff; width: 100%;
  box-shadow: var(--shadow-xs); transition: border-color 150ms ease, box-shadow 150ms ease;
}
textarea.input { line-height: 1.5; resize: vertical; }
select.input:not([multiple]) {
  -webkit-appearance: none; appearance: none; padding-right: 36px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235b7166' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 13px center;
}
.input::placeholder { color: #93a69b; }
.input:focus, .input:focus-visible { outline: none; border-color: var(--brand-2); box-shadow: var(--ring); }
.input[readonly] { background: var(--brand-tint); color: var(--muted); }
.input:disabled { background: #f3f6f4; color: var(--muted); cursor: not-allowed; }
input[type="file"].input { padding: 7px 8px; cursor: pointer; }
input[type="file"].input::file-selector-button {
  margin-right: 10px; border: 0; border-radius: 8px; padding: 6px 12px; background: var(--brand-soft); color: var(--brand); font-weight: 700; cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-2); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 180px; }

/* Tables */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; background: #f8fbf9; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td small { display: block; color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace; letter-spacing: .02em; }

/* Status */
.status {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px 3px 8px;
  font-size: 13px; font-weight: 700; white-space: nowrap; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .04);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status.good { background: var(--brand-soft); color: var(--brand); }
.status.bad { background: var(--red-soft); color: var(--red); }
.status.wait { background: var(--amber-soft); color: var(--amber); }
.message {
  border-radius: 12px; padding: 12px 14px; background: var(--brand-soft); color: var(--brand); font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(7 91 59 / .08);
}
.message.warn { background: var(--amber-soft); color: var(--amber); box-shadow: inset 0 0 0 1px rgb(168 109 18 / .12); }
.message.error { background: var(--red-soft); color: var(--red); box-shadow: inset 0 0 0 1px rgb(194 65 79 / .12); }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.placeholder { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); background: #fff; }
.placeholder b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* Loading & toast */
.spinner {
  width: 18px; height: 18px; border: 3px solid #12834d2e; border-top-color: var(--brand-2); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 18px; }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100; max-width: calc(100% - 32px);
  background: #0f2a1e; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow-pop);
  opacity: 0; transform: translate(-50%, calc(100% + 28px)); pointer-events: none;
  transition: transform 400ms ease, opacity 400ms ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

/* Modal: кіру 250 мс, шығу 150 мс; ортада тұрғандықтан transform-origin — center */
.modal-backdrop {
  position: fixed; inset: 0; background: rgb(9 32 22 / .45); display: none; align-items: center; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal-backdrop.open { display: flex; animation: fade-in 200ms ease both; }
.modal {
  background: #fff; border-radius: 18px; padding: 24px; width: min(560px, 100%); max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  box-shadow: var(--shadow-pop); overscroll-behavior: contain;
}
.modal-backdrop.open > .modal { animation: modal-in 250ms var(--ease-out) both; }
.modal-backdrop.closing { animation: fade-out 150ms ease forwards; pointer-events: none; }
.modal-backdrop.closing > .modal { animation: modal-out 150ms var(--ease-out) forwards; }
.modal h2 { margin-top: 0; letter-spacing: -0.01em; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes modal-out { to { opacity: 0; transform: scale(0.97); } }

/* Login */
.login-page {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(900px 480px at 12% -8%, #1a9a5c66 0%, transparent 62%),
    radial-gradient(700px 380px at 100% 0%, #04452b99 0%, transparent 60%),
    linear-gradient(165deg, var(--brand) 0%, #0b6e47 44%, var(--bg) calc(44% + 1px));
}
.login-card {
  width: min(420px, 100%); background: #fff; border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow-pop);
  animation: rise-in 500ms var(--ease-out) both;
}
.login-card .brand { color: var(--brand); padding: 0 0 20px; }
.login-card .brand-mark { background: var(--brand); color: #fff; box-shadow: 0 4px 12px -2px rgb(7 91 59 / .45), inset 0 1px 0 #ffffff33; }
.login-title { font-size: 24px; margin: 0; letter-spacing: -0.02em; line-height: 1.25; }
.login-lead { margin: 6px 0 0; }
.btn.block { width: 100%; }
.login-card .btn.primary { min-height: 46px; font-size: 16px; }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } }

/* Hover — тек тінтуірі бар құрылғыларда (сенсорда «жабысып» қалмауы үшін) */
@media (hover: hover) and (pointer: fine) {
  .navbtn:hover { background: #ffffff14; color: #fff; }
  .navbtn.active:hover { background: #ffffff1f; }
  .btn:hover:not(:disabled) { border-color: #a9c9b5; background: var(--brand-tint); }
  .btn.primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
  .btn.danger:hover:not(:disabled) { background: var(--red-soft); border-color: #e7aab2; }
  .input:hover:not(:focus):not(:disabled) { border-color: #a9c9b5; }
  tbody tr:hover td { background: #f7fbf8; }
  button.card:hover { border-color: #b9d6c4; box-shadow: var(--shadow-lift); }
}

/* Сенсорлы экран: батырмалар кемінде ~44px */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .input, select.input, textarea.input { min-height: 46px; font-size: 16px; }
}

/* Print cards */
.print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { display: grid !important; position: absolute; inset: 0; grid-template-columns: 1fr 1fr; gap: 8mm; padding: 8mm; }
  .cred-card { border: 1px dashed #333; border-radius: 6px; padding: 6mm; break-inside: avoid; font-size: 13pt; color: #000; }
  .cred-card h3 { margin: 0 0 3mm; font-size: 12pt; }
  .cred-card .row { margin: 1.5mm 0; }
  .cred-card .mono { font-size: 14pt; font-weight: 700; }
}

/* Mobile: бүйір мәзір — iOS тәрізді drawer */
@media (max-width: 860px) {
  .sidebar {
    width: 280px; max-width: 86vw; transform: translateX(-100%); visibility: hidden;
    transition: transform 320ms var(--ease-drawer), visibility 0s linear 320ms;
    padding-top: calc(22px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); visibility: visible; box-shadow: var(--shadow-pop); transition: transform 320ms var(--ease-drawer), visibility 0s; }
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 19; background: rgb(9 32 22 / .4);
    opacity: 0; pointer-events: none; transition: opacity 250ms ease;
  }
  .sidebar.open + .sidebar-scrim { opacity: 1; pointer-events: auto; transition-duration: 320ms; }
  .main { margin-left: 0; padding: 0 16px 32px; }
  .topbar { height: 64px; margin: 0 -16px 18px; padding: 0 16px; }
  .btn.menu-toggle { display: inline-flex; min-width: 40px; }
  .topbar h1 { font-size: 19px; }
  .whoami .name { display: none; }
  /* Phone top bar: one line, nothing pushes the page wider than the screen. */
  .topbar { gap: 8px; }
  .topbar > .btn-row { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 8px; }
  .topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
  .whoami { flex-shrink: 0; gap: 6px; }
  .whoami .role-chip { display: none; }
  .avatar { width: 32px; height: 32px; }
  .centre-picker { flex-shrink: 0; margin-left: 0; }
  .centre-picker > span { display: none; }
  .centre-picker .input { min-width: 0; width: 118px; max-width: 118px; min-height: 38px; padding: 4px 28px 4px 10px; font-size: 14px; }
  .main { overflow-x: clip; }
  /* Nothing on a phone may make the page wider than the screen. */
  html, body { overflow-x: hidden; max-width: 100%; }
  .layout { max-width: 100vw; }
  .card, .message, .empty { overflow-wrap: anywhere; min-width: 0; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid.stats .card { padding: 14px; }
  .btn { white-space: normal; text-align: center; }
  img, svg, video { max-width: 100%; height: auto; }
  .toolbar .input { width: 100%; }
  .card { padding: 16px; }
  .stat-value { font-size: 26px; }
}

/* Телефонда модаль төменнен шығатын парақ (sheet) болады */
@media (max-width: 560px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 22px 22px 0 0;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  }
  .modal-backdrop.open > .modal { animation: sheet-in 420ms var(--ease-drawer) both; }
  .modal-backdrop.closing > .modal { animation: sheet-out 200ms var(--ease-out) forwards; }
  .modal-backdrop.closing { animation-duration: 200ms; }
  .modal .btn-row > .btn { flex: 1 1 auto; }
  .login-card { padding: 28px 20px; border-radius: 20px; }
}
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }

/* Қозғалысты азайту: орын ауыстыру жоқ, тек мөлдірлік */
@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled), .navbtn:active, button.card:active { transform: none; }
  .modal-backdrop.open > .modal, .login-card { animation: fade-in 200ms ease both; }
  .modal-backdrop.closing > .modal { animation: fade-out 150ms ease forwards; }
  #toast { transform: translate(-50%, 0); transition: opacity 200ms ease; }
  .sidebar, .sidebar.open { transition: none; }
}
