/* ==========================================================
   DORIAN'S TIMETABLE v3 — ADMIN
   Same tokens as the public app (css/tokens.css), but denser:
   this screen is operated, not read. Mobile first — most edits
   will happen from a phone.
   ========================================================== */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { overflow-x: hidden; max-width: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

.muted { color: var(--text-soft); font-size: 0.88rem; line-height: 1.5; margin: 0; }
.pad { padding: 22px 4px; }
.warn {
    margin: 0 0 12px;
    padding: 10px 14px;
    border-left: 3px solid var(--accent-b);
    border-radius: 0 10px 10px 0;
    background: color-mix(in srgb, var(--accent-b) 10%, transparent);
    color: var(--text);
    font-size: 0.85rem;
    line-height: 1.5;
}
.warn a { color: var(--accent-a); font-weight: 700; text-decoration: underline; }
.warn a:hover { color: var(--accent-b); }
.empty {
    margin: 0;
    padding: 30px 16px;
    text-align: center;
    color: var(--text-soft);
    font-weight: 600;
}

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 20px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}
.btn:hover { border-color: var(--accent-a); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.small { padding: 8px 14px; font-size: 0.82rem; }
.btn.primary {
    background: var(--hero-grad);
    color: var(--hero-text);
    border-color: transparent;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent-b) 28%, transparent);
}
.btn.ghost { background: transparent; }
.btn.danger { background: var(--accent-b); border-color: transparent; color: #fff; }
.btn.danger-text { color: var(--accent-b); }
.btn.danger-text:hover { border-color: var(--accent-b); }

.icon-btn {
    flex: none;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-soft);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--line); }

:where(button, a, input, select, textarea, summary):focus-visible {
    outline: 2px solid var(--accent-a);
    outline-offset: 2px;
}

/* ---------------- Login ---------------- */
.login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 32px 26px;
    background: var(--card-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.login-card img { align-self: center; border-radius: 14px; }
.login-card h1 { font-size: 1.5rem; font-weight: 800; text-align: center; }
.login-card .muted { text-align: center; margin-bottom: 4px; }
.login-card .btn { margin-top: 6px; }

/* ---------------- Top bar ---------------- */
.admin-top {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 0.95rem; }

/* Back to the timetable. The installed app has no browser toolbar, so this
   is the only way out of the panel. */
.icon-sm {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 38px;
    height: 38px;
    margin-left: -4px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--card);
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.icon-back:hover { color: var(--accent-a); border-color: var(--accent-a); }
.icon-back:active { transform: translateX(-2px); }

.back-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-top: 18px;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
}
.back-text:hover { color: var(--accent-a); }
.brand-badge {
    padding: 4px 11px;
    border-radius: 999px;
    background: var(--hero-grad);
    color: var(--hero-text);
    font-size: 0.78rem;
    font-weight: 800;
}
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* On a phone the top bar keeps only what is needed to navigate: back, the
   class badge, and the account controls. The title is already in the browser
   tab, and the address is on the Settings tab. Both come back on wide screens. */
.admin-email,
#brand-title { display: none; }

@media (min-width: 700px) {
    #brand-title { display: inline; }
    .admin-email {
        display: inline;
        color: var(--text-soft);
        font-size: 0.8rem;
        font-weight: 600;
    }
}

/* ---------------- Tabs ---------------- */
.tabs {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    flex: none;
    padding: 9px 16px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--text-soft);
    font: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
    background: var(--hero-grad);
    border-color: transparent;
    color: var(--hero-text);
}

/* ---------------- Panel ---------------- */
.panel {
    max-width: 900px;
    margin: 0 auto;
    padding: 6px 16px calc(60px + env(safe-area-inset-bottom));
}
.panel-section { margin-top: 26px; }
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.section-head h2 {
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 2.2px;
    text-transform: uppercase;
    color: var(--text-soft);
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
/* Intro line under a section heading needs room before the first field. */
.panel-section > .muted { margin-bottom: 14px; }

/* ---------------- Forms ---------------- */
.admin-form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row.tight { gap: 4px; }
.form-label {
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-soft);
}
.form-label .opt { text-transform: none; letter-spacing: 0; font-weight: 600; opacity: 0.75; }
.form-sublabel { font-size: 0.74rem; font-weight: 700; color: var(--text-soft); margin-top: 4px; }
.form-hint { margin: 0; font-size: 0.78rem; color: var(--text-soft); }
.form-error { margin: 0; font-size: 0.78rem; font-weight: 700; color: var(--accent-b); }

.input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card-solid);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
}
.input:focus { border-color: var(--accent-a); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-a) 18%, transparent); }
.input.invalid { border-color: var(--accent-b); }
.input.tiny { width: auto; flex: 1 1 90px; min-width: 0; padding: 8px 10px; font-size: 0.85rem; }
textarea.input { resize: vertical; min-height: 76px; line-height: 1.5; }
input[type="color"].input { height: 44px; padding: 4px; cursor: pointer; }

/* ---------------- Markdown editor ---------------- */
.md-editor { display: flex; flex-direction: column; gap: 6px; }

.md-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.md-btn {
    min-width: 38px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--card-solid);
    color: var(--text-soft);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}
.md-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent-a) 45%, var(--line)); }
.md-btn:active { transform: translateY(1px); }
.md-btn.bold { font-weight: 900; font-size: 0.95rem; }
.md-btn.italic { font-style: italic; font-family: Georgia, serif; font-size: 0.98rem; }
.md-btn.list { letter-spacing: -1px; }
.md-btn.wide { margin-left: auto; font-size: 0.78rem; font-weight: 700; }
.md-btn.on { background: color-mix(in srgb, var(--accent-a) 18%, var(--card-solid)); border-color: var(--accent-a); color: var(--text); }

.md-preview {
    min-height: 76px;
    padding: 11px 14px;
    border: 1px dashed var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent-a) 5%, var(--card-solid));
    font-size: 0.92rem;
    line-height: 1.55;
}
.md-preview .muted { margin: 0; }

.check-row, .check-inline {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.check-inline { font-size: 0.78rem; color: var(--text-soft); white-space: nowrap; }
.check-row input, .check-inline input { width: 18px; height: 18px; accent-color: var(--accent-a); cursor: pointer; }

.more-langs { margin-top: 4px; }
.more-langs summary {
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-a);
    padding: 4px 0;
}
.more-langs[open] { padding-bottom: 4px; }

/* ---------------- Timetable grid ---------------- */
.tt-grid {
    --cols: 5;
    display: grid;
    grid-template-columns: 42px repeat(var(--cols), minmax(0, 1fr));
    gap: 5px;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.tt-corner, .tt-head {
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-soft);
    text-align: center;
    padding-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tt-corner { text-align: left; }
.tt-period {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}
.tt-period strong { font-size: 0.9rem; color: var(--text); }
.tt-period span { font-size: 0.58rem; }
.tt-cell {
    min-height: 46px;
    padding: 4px 2px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--subj) 16%, transparent);
    color: color-mix(in srgb, var(--subj) calc(100% - var(--subj-text-pct)), var(--subj-text-mix));
    font: inherit;
    font-weight: 800;
    font-size: 0.68rem;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: transform 0.12s ease, border-color 0.2s ease;
}
.tt-cell:hover { border-color: color-mix(in srgb, var(--subj, var(--accent-a)) 55%, transparent); transform: translateY(-1px); }
.tt-cell.free {
    background: transparent;
    border: 1px dashed var(--line);
    color: var(--text-soft);
    font-size: 1rem;
}

/* Subject picker inside the sheet */
.subject-picker { display: flex; flex-direction: column; gap: 6px; }
.pick {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.pick:hover { border-color: color-mix(in srgb, var(--subj, var(--accent-a)) 60%, transparent); }
.pick.active { border-color: var(--accent-a); background: var(--today-tint); }
.pick .dot { flex: none; width: 14px; height: 14px; border-radius: 5px; background: var(--subj, var(--text-soft)); }
.pick-name { flex: 1; min-width: 0; }
.pick-key { font-size: 0.74rem; font-weight: 800; color: var(--text-soft); text-transform: uppercase; letter-spacing: 1px; }
.pick.free { justify-content: center; color: var(--text-soft); font-weight: 700; }

/* ---------------- Lists ---------------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.list-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 14px;
}
.list-card.dim { opacity: 0.5; }
.list-main { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.list-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-title-row h3 { font-size: 1rem; font-weight: 800; overflow-wrap: anywhere; }
.list-meta { margin: 0; font-size: 0.82rem; color: var(--text-soft); font-weight: 600; }
.list-note { margin: 4px 0 0; font-size: 0.86rem; color: var(--text-soft); line-height: 1.5; overflow-wrap: anywhere; }
.list-actions { display: flex; gap: 6px; flex: none; }

.chip {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.chip.soon { background: color-mix(in srgb, var(--accent-c) 16%, transparent); color: var(--accent-c); }
.chip.past { background: color-mix(in srgb, var(--text-soft) 16%, transparent); color: var(--text-soft); }

/* ---------------- Bell times ---------------- */
.bell-grid { display: grid; gap: 18px; grid-template-columns: 1fr; }
.bell-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.bell-col h3 {
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--accent-c);
    margin-bottom: 2px;
}
.bell-slot {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.bell-slot.is-break { border-style: dashed; background: color-mix(in srgb, var(--accent-b) 7%, transparent); }
.bell-slot .dash { color: var(--text-soft); }
/* Break toggle and delete stay together and hug the right edge, so the
   × never wraps onto a line of its own. */
.slot-tail { display: flex; align-items: center; gap: 4px; margin-left: auto; }

/* ---------------- Subjects ---------------- */
.subject-list { display: flex; flex-direction: column; gap: 8px; }
.subject-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
}
.subject-row.dim { opacity: 0.5; }
.subject-row .dot { flex: none; width: 14px; height: 14px; border-radius: 5px; background: var(--subj); }
.subject-names { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.subject-names strong { font-size: 0.92rem; overflow-wrap: anywhere; }
.subject-names .muted { font-size: 0.72rem; letter-spacing: 0.3px; font-weight: 600; line-height: 1.4; }

/* An e-mail plus a role picker plus a delete button will not fit one phone
   line, and squeezing them breaks the address mid-word. Give the address the
   full width and let the controls sit underneath it. */
.admin-row { flex-wrap: wrap; }
.admin-row .subject-names { flex: 1 1 100%; }
.admin-row .list-actions,
.admin-row .chip { margin-left: auto; }
.role-select { flex: none; width: auto; min-width: 140px; }

/* ---------------- Sheet ---------------- */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background: color-mix(in srgb, var(--bg) 62%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.2s ease;
}
.sheet-overlay.open { opacity: 1; }
.sheet-panel {
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--card-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.4);
    transform: translateY(18px);
    transition: transform 0.24s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.sheet-overlay.open .sheet-panel { transform: translateY(0); }
.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 12px;
    border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 1.05rem; font-weight: 800; overflow-wrap: anywhere; }
.sheet-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.sheet-actions .btn { flex: 1 1 auto; }

/* ---------------- Toast ---------------- */
#toast-host {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 200;
    transform: translateX(-50%);
    width: min(460px, calc(100vw - 24px));
    pointer-events: none;
}
.admin-toast {
    padding: 12px 18px;
    border-radius: 14px;
    background: var(--card-solid);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
    animation: toastIn 0.24s ease;
}
.admin-toast.ok { border-color: color-mix(in srgb, var(--accent-c) 45%, transparent); color: var(--accent-c); }
.admin-toast.error { border-color: color-mix(in srgb, var(--accent-b) 50%, transparent); color: var(--accent-b); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Wider screens ---------------- */
@media (min-width: 700px) {
    .bell-grid { grid-template-columns: 1fr 1fr; }
    .sheet-overlay { align-items: center; padding: 24px; }
    .sheet-panel { border-radius: var(--radius); }
    .sheet-actions { justify-content: flex-end; }
    .sheet-actions .btn { flex: 0 0 auto; }
    .tt-cell { font-size: 0.78rem; min-height: 54px; }
    .admin-email { max-width: none; }
}

@media (max-width: 380px) {
    .admin-top { padding-left: 12px; padding-right: 12px; }
    .tabs, .panel { padding-left: 12px; padding-right: 12px; }
    .tt-grid { gap: 4px; padding: 8px; }
    .tt-cell { font-size: 0.62rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
