:root {
  --bg: #f4efe7;
  --bg-2: #e8dccd;
  --panel: rgba(255, 252, 247, 0.84);
  --text: #211913;
  --muted: #706257;
  --line: #dacdbe;
  --primary: #7a5634;
  --primary-dark: #5f4025;
  --accent: #b9976b;
  --danger: #9d332b;
  --success: #52764d;
  --warning: #b7782b;
  --shadow: 0 20px 60px rgba(67, 47, 31, .14);
  --radius: 22px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(185, 151, 107, .28), transparent 34%),
    radial-gradient(circle at 100% 20%, rgba(122, 86, 52, .16), transparent 32%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

button, input, select, textarea { font: inherit; }
button, a.link-button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: .72rem 1rem;
  font-weight: 750;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
button:hover, a.link-button:hover { transform: translateY(-1px); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.78);
  border-radius: 14px;
  padding: .72rem .82rem;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(122, 86, 52, .12); }
label { display: grid; gap: .35rem; color: var(--muted); font-size: .9rem; font-weight: 650; }
textarea { min-height: 96px; resize: vertical; }

.primary { background: var(--primary); color: #fff; box-shadow: 0 10px 24px rgba(122, 86, 52, .25); }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #fff7ed; color: var(--primary-dark); border: 1px solid var(--line); }
.ghost { background: transparent; color: var(--primary-dark); padding-inline: 0; }
.danger { background: #fff0ef; color: var(--danger); border: 1px solid #e8b8b3; }
a.link-button { display: inline-flex; text-decoration: none; background: #fff7ed; color: var(--primary-dark); border: 1px solid var(--line); }
.hidden { display: none !important; }
.glass { background: var(--panel); border: 1px solid rgba(255,255,255,.66); box-shadow: var(--shadow); backdrop-filter: blur(16px); }

.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.auth-card { width: min(560px, 100%); border-radius: 30px; padding: 2rem; }
.brand-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.4rem; }
.brand-row.compact { margin-bottom: 2rem; }
.brand-mark { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--primary), var(--accent)); font-weight: 900; font-size: 1.4rem; box-shadow: 0 12px 28px rgba(122,86,52,.24); }
.brand-row h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.25rem); }
.brand-row p, .brand-row small { margin: .15rem 0 0; color: var(--muted); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin: 1.2rem 0; background: rgba(255,255,255,.5); padding: .35rem; border-radius: 999px; }
.tab { background: transparent; color: var(--muted); box-shadow: none; }
.tab.active { background: #fff; color: var(--primary-dark); box-shadow: 0 8px 20px rgba(67,47,31,.08); }
.auth-form { display: grid; gap: .9rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; gap: 1.2rem; padding: 1.2rem; }
.sidebar { border-radius: var(--radius); padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 1.2rem; height: calc(100vh - 2.4rem); }
.side-nav { display: grid; gap: .55rem; }
.nav-item { width: 100%; text-align: left; background: transparent; color: var(--muted); border-radius: 16px; }
.nav-item.active { background: #fff; color: var(--primary-dark); box-shadow: 0 8px 18px rgba(67,47,31,.08); }
.user-box { margin-top: auto; border-top: 1px solid var(--line); padding-top: 1rem; display: grid; gap: .3rem; }
.user-box small { color: var(--muted); }
.content { display: grid; gap: 1rem; align-content: start; min-width: 0; }
.topbar { border-radius: var(--radius); padding: 1.1rem 1.25rem; display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.topbar h2 { margin: 0; font-size: clamp(1.4rem, 2vw, 2rem); }
.topbar p { margin: .25rem 0 0; color: var(--muted); }
.toolbar { border-radius: var(--radius); padding: 1rem; display: grid; grid-template-columns: auto 170px auto 150px minmax(180px, 1fr) auto; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.check-row { display: flex; align-items: center; gap: .5rem; white-space: nowrap; padding-bottom: .7rem; }
.check-row input { width: auto; }
.status-line { min-height: 1.3rem; margin: .25rem .2rem .7rem; color: var(--muted); }
.calendar-wrap { border-radius: var(--radius); overflow: auto; }
.calendar-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 850px; }
.calendar-table th, .calendar-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: top; }
.calendar-table th { position: sticky; top: 0; background: #fff9f1; padding: .9rem; text-align: left; z-index: 1; }
.calendar-table th:first-child, .calendar-table td:first-child { border-left: 0; }
.calendar-table tr:last-child td { border-bottom: 0; }
.slot-label { width: 130px; background: rgba(255,255,255,.6); padding: .75rem; font-weight: 800; color: var(--primary-dark); }
.slot-label small { display: block; color: var(--muted); font-weight: 600; margin-top: .15rem; }
.calendar-cell { min-height: 92px; padding: .55rem; background: rgba(255,255,255,.42); transition: background .16s ease; }
.calendar-cell:hover { background: rgba(255,255,255,.74); }
.empty-cell { color: var(--muted); font-size: .82rem; display: grid; place-items: center; min-height: 72px; border: 1px dashed rgba(122,86,52,.18); border-radius: 16px; }
.reservation-card { border-left: 5px solid var(--primary); background: #fff; border-radius: 16px; padding: .65rem; box-shadow: 0 8px 18px rgba(67,47,31,.08); display: grid; gap: .25rem; cursor: pointer; }
.reservation-card strong { font-size: .92rem; }
.reservation-card small { color: var(--muted); }
.reservation-card.pending { border-left-color: var(--warning); }
.reservation-card.mine { outline: 2px solid rgba(82,118,77,.18); }
.badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; padding: .2rem .5rem; font-size: .75rem; font-weight: 800; background: #f4eadc; color: var(--primary-dark); }
.badge.success { background: #edf5ea; color: var(--success); }
.badge.warn { background: #fff3df; color: var(--warning); }
.badge.danger { background: #fff0ef; color: var(--danger); }

.panel { border-radius: var(--radius); padding: 1.1rem; }
.panel h3 { margin: 0 0 1rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: .7rem; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
.wide { grid-column: 1 / -1; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: .85rem; }
.stat strong { display: block; font-size: 1.7rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.table-list { display: grid; gap: .55rem; }
.row-card { display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: center; background: rgba(255,255,255,.7); border: 1px solid var(--line); border-radius: 18px; padding: .8rem; }
.row-card small { color: var(--muted); display: block; margin-top: .2rem; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .75rem; }
.import-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; align-items: center; }
.import-row input { max-width: 240px; }
.settings-form { display: grid; gap: 1rem; }
.lesson-grid { display: grid; gap: .55rem; }
.lesson-row { display: grid; grid-template-columns: 1fr 120px 120px auto; gap: .5rem; align-items: end; }
.audit-list { max-height: 360px; overflow: auto; display: grid; gap: .5rem; }
.audit-item { background: rgba(255,255,255,.68); border: 1px solid var(--line); border-radius: 16px; padding: .7rem; }
.audit-item small { color: var(--muted); }

.modal { border: 0; background: transparent; width: min(680px, calc(100% - 2rem)); padding: 0; }
.modal::backdrop { background: rgba(31, 22, 15, .45); backdrop-filter: blur(5px); }
.modal-card { position: relative; border-radius: 28px; background: #fffaf4; border: 1px solid #fff; padding: 1.2rem; box-shadow: 0 26px 90px rgba(31,22,15,.34); display: grid; gap: .85rem; }
.modal-close { position: absolute; right: .8rem; top: .8rem; background: transparent; font-size: 1.5rem; padding: .2rem .45rem; color: var(--muted); }
.modal h3 { margin: .2rem 2rem .5rem 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .85rem; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.toast-root { position: fixed; right: 1rem; bottom: 1rem; z-index: 1000; display: grid; gap: .5rem; }
.toast { background: #fff; border-left: 5px solid var(--primary); border-radius: 16px; box-shadow: var(--shadow); padding: .85rem 1rem; min-width: 260px; max-width: 420px; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warn { border-left-color: var(--warning); }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .toolbar { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .admin-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .auth-layout, .app-shell { padding: .75rem; }
  .auth-card, .topbar, .toolbar, .panel { border-radius: 18px; }
  .tabs { grid-template-columns: 1fr; border-radius: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .toolbar, .form-grid, .lesson-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}

.top-actions { display: flex; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
.badge-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.notice { background: #fff7ed; border: 1px solid var(--line); border-radius: 16px; padding: .75rem; color: var(--primary-dark); }
.muted-text, .muted-control small { color: var(--muted); }
.error-text { color: var(--danger); font-weight: 700; }
.repeat-box { border: 1px solid var(--line); border-radius: 18px; padding: .85rem; background: rgba(255,255,255,.5); }
.repeat-box legend { padding: 0 .4rem; color: var(--primary-dark); font-weight: 850; }
.repeat-weekdays { display: grid; gap: .4rem; }
.repeat-weekdays > span { color: var(--muted); font-size: .9rem; font-weight: 750; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: .45rem; }
.weekday-picker label { display: inline-flex; align-items: center; gap: .25rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; padding: .35rem .55rem; color: var(--text); }
.weekday-picker input { width: auto; }
.mobile-agenda { display: none; gap: .85rem; }
.mobile-day-card { background: rgba(255,255,255,.7); border: 1px solid var(--line); border-radius: 20px; padding: .85rem; box-shadow: 0 12px 28px rgba(67,47,31,.08); }
.mobile-day-card h4 { margin: 0 0 .7rem; color: var(--primary-dark); }
.mobile-slot-list { display: grid; gap: .55rem; }
.mobile-slot { display: grid; grid-template-columns: 92px 1fr; gap: .55rem; align-items: start; }
.mobile-slot-time { color: var(--primary-dark); font-size: .88rem; }
.mobile-slot-time small { display: block; color: var(--muted); margin-top: .15rem; }
.mobile-slot-body { display: grid; gap: .45rem; min-width: 0; }
.mobile-empty { min-height: auto; width: 100%; background: rgba(255,255,255,.62); }
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .7rem; }
.help-grid article, .contact-card { background: rgba(255,255,255,.65); border: 1px solid var(--line); border-radius: 18px; padding: .85rem; }
.help-grid p, .contact-card p { margin: .35rem 0; color: var(--muted); }
.usage-stats { display: grid; gap: 1rem; }
.usage-summary { margin-bottom: .2rem; }
.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.usage-block { background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 18px; padding: .85rem; display: grid; gap: .65rem; }
.usage-block h4 { margin: 0; }
.usage-row { display: grid; grid-template-columns: minmax(130px, 210px) 1fr; gap: .65rem; align-items: center; }
.usage-label small { display: block; color: var(--muted); margin-top: .1rem; }
.usage-bar { height: 10px; border-radius: 999px; background: #efe3d4; overflow: hidden; }
.usage-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.tour-overlay { position: fixed; inset: 0; z-index: 2000; pointer-events: auto; }
.tour-backdrop { position: absolute; inset: 0; background: rgba(31,22,15,.42); backdrop-filter: blur(2px); }
.tour-highlight { position: fixed; z-index: 2001; border: 3px solid #fff8e9; border-radius: 18px; box-shadow: 0 0 0 9999px rgba(31,22,15,.42), 0 16px 50px rgba(0,0,0,.24); pointer-events: none; }
.tour-card { position: fixed; z-index: 2002; background: #fffaf4; border: 1px solid #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 1rem; }
.tour-card h3 { margin: .55rem 0 .35rem; }
.tour-card p { color: var(--muted); }

@media (max-width: 820px) {
  .calendar-wrap { display: none; }
  .mobile-agenda { display: grid; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions button { flex: 1 1 170px; }
  .usage-grid, .help-grid { grid-template-columns: 1fr; }
  .usage-row { grid-template-columns: 1fr; gap: .35rem; }
}

@media (max-width: 720px) {
  button, a.link-button { padding: .82rem 1rem; }
  input, select, textarea { min-height: 44px; }
  .app-shell { gap: .75rem; }
  .sidebar { padding: .9rem; gap: .8rem; }
  .brand-row.compact { margin-bottom: .2rem; }
  .side-nav { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .nav-item { text-align: center; padding-inline: .5rem; }
  .user-box { margin-top: .2rem; grid-template-columns: 1fr auto; align-items: center; }
  .user-box small { grid-column: 1; }
  #logout-btn { grid-row: 1 / span 2; grid-column: 2; }
  .row-card { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .modal { width: calc(100% - 1rem); }
  .modal-card { border-radius: 22px; padding: 1rem; max-height: calc(100vh - 1.4rem); overflow: auto; }
  .toast-root { left: .75rem; right: .75rem; bottom: .75rem; }
  .toast { min-width: 0; max-width: none; }
}

@media (max-width: 460px) {
  .auth-layout, .app-shell { padding: .55rem; }
  .brand-mark { width: 46px; height: 46px; border-radius: 15px; }
  .toolbar { gap: .55rem; }
  .mobile-slot { grid-template-columns: 1fr; }
  .weekday-picker label { flex: 1 1 64px; justify-content: center; }
}

.dialog-fallback[open] { position: fixed; inset: 50% auto auto 50%; transform: translate(-50%, -50%); z-index: 1600; }
.dialog-fallback[open]::before { content: ''; position: fixed; inset: -100vh -100vw; background: rgba(31,22,15,.45); backdrop-filter: blur(5px); z-index: -1; }
