/* Portal layout on top of /styles.css theme tokens */
:root { --sidebar-bg: #fffdf8; --sidebar-text: #2b241d; --sidebar-muted: #6d6257; --sidebar-active: rgba(200,155,82,.18); }
:root[data-theme="dark"] { --sidebar-bg: #0f0c09; --sidebar-text: #f8f4ec; --sidebar-muted: #bdb1a1; --sidebar-active: rgba(200,155,82,.16); }
body.portal { background: var(--bg); font-size: 15.5px; }
.boot { min-height: 100vh; display: grid; place-items: center; font-family: var(--serif); font-size: 2rem; color: var(--accent-text); background: var(--bg); }
.portal h1 { font-size: clamp(1.9rem, 3vw, 2.5rem); margin: 0; }
.portal h2 { font-size: 1.45rem; margin: 0 0 12px; }
.portal h3 { font-size: 1.2rem; margin: 0 0 4px; font-family: var(--sans); font-weight: 700; }
.muted, .hint, .meta { color: var(--muted); }
.hint { font-size: .9rem; }
.meta { font-size: .85rem; margin: 2px 0; }
.pre { white-space: pre-wrap; margin: 6px 0 0; }
.private { color: var(--accent-text); font-size: .85rem; }
.empty { color: var(--muted); padding: 20px 0; margin: 0; }
code { font-size: .85em; background: var(--tint); padding: 1px 6px; border-radius: 4px; }

.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-muted); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 10px 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: .95rem; display: flex; justify-content: space-between; align-items: center; color: var(--sidebar-muted); }
.sidebar nav a:hover { background: var(--menu-hover); color: var(--sidebar-text); }
.sidebar nav a.active { background: var(--sidebar-active); color: var(--sidebar-text); font-weight: 600; }
.badge { background: var(--accent); color: var(--on-accent); border-radius: 999px; font-size: .72rem; font-weight: 700; padding: 1px 8px; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 16px 10px 0; display: flex; flex-direction: column; gap: 12px; }
.who { display: flex; flex-direction: column; }
.who strong { color: var(--sidebar-text); }
.who span { font-size: .8rem; color: var(--accent-text); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 32px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.topbar-site { text-decoration: none; color: var(--muted); font-size: .9rem; margin-right: auto; }
.topbar-site:hover { color: var(--text); }
.menu-btn { display: none; }
.content { padding: 28px 32px 64px; max-width: 1200px; width: 100%; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .25s; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 20px 16px 48px; }
}


/* Buttons */
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; font-size: 1.3rem; cursor: pointer; color: var(--text); align-items: center; justify-content: center; }
.btn-danger { background: transparent; color: #b4432c; border-color: #e0b1a5; }
.btn-danger:hover { background: #b4432c; color: #fff; border-color: #b4432c; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.file-btn { cursor: pointer; }
.sidebar .btn-ghost { color: var(--sidebar-text); border-color: var(--line); }
.sidebar .btn-ghost:hover { background: var(--menu-hover); color: var(--sidebar-text); border-color: var(--muted); }

/* Page structure */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-actions, .row-actions, .form-actions, .share { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
td.row-actions { display: table-cell; text-align: right; white-space: nowrap; }
td.row-actions .btn { margin: 2px 0 2px 6px; }
.back { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 18px; }
.card-accent { border-color: var(--gold); box-shadow: inset 4px 0 0 var(--gold); }
.card .more { display: inline-block; margin-top: 10px; font-size: .88rem; color: var(--accent-text); font-weight: 700; text-decoration: none; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.dash-grid .card { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--band); color: var(--band-muted); border: 1px solid var(--band-line); border-radius: var(--radius); padding: 18px 20px; text-decoration: none; display: flex; flex-direction: column; }
.stat strong { font-family: var(--sans); font-weight: 700; font-size: 2.1rem; color: var(--accent-text); line-height: 1; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li span:not(.chip) { color: var(--muted); font-size: .88rem; flex: 1 1 auto; }
.list li strong { flex: 1 1 100%; }
.section-block { margin-top: 30px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.block-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg .card { margin-bottom: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .92rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--heading); border-bottom-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td a { color: var(--text); }
td small { color: var(--muted); }
td.notes { max-width: 280px; white-space: pre-wrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--tint); }

/* Item cards (homework, materials, requests) */
.cards-list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; gap: 16px; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.item-main { min-width: 0; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.item.status-reviewed { opacity: .7; }
.feedback { background: var(--tint); border-radius: 8px; padding: 8px 12px; margin: 8px 0 0; font-size: .92rem; }
@media (max-width: 640px) { .item { flex-direction: column; } .item-side { flex-direction: row; flex-wrap: wrap; align-items: center; } }
.announcement + .btn { margin-top: 10px; }
.announcement h3 { font-size: 1.15rem; }
.card > .announcement { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.card > .announcement:last-of-type { border-bottom: 0; margin-bottom: 0; }
.dash-grid .announcement .pre { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Chips */
.chip { display: inline-block; font-size: .74rem; font-weight: 700; letter-spacing: .03em; padding: 3px 10px; border-radius: 999px; background: var(--tint); color: var(--text); white-space: nowrap; font-family: var(--sans); vertical-align: middle; }
.chip-active, .chip-done, .chip-reviewed, .chip-completed, .chip-published, .chip-paid { background: #e3efd9; color: #3c6b27; }
.chip-pending, .chip-proposed, .chip-assigned, .chip-draft { background: #fbecd0; color: #8a5a10; }
.chip-scheduled, .chip-registered { background: #dde8f5; color: #2b5687; }
.chip-disabled, .chip-rejected, .chip-cancelled, .chip-withdrawn { background: #f1dcd6; color: #9b3a23; }

/* Info list */
.info { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 24px; margin: 0; }
.info dt { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.info dd { margin: 2px 0 0; word-break: break-word; }

/* Forms */
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid-form .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } }
.portal label, .portal .label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.portal label small { font-weight: 400; }
.portal input:not([type=checkbox]):not([type=radio]):not([type=file]), .portal select, .portal textarea {
  font: inherit; font-size: .98rem; color: var(--text); background: var(--field-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.portal input:focus, .portal select:focus, .portal textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.portal textarea.md { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92rem; line-height: 1.6; }
.portal input[type=file] { font-size: .9rem; }
.portal fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.portal fieldset[hidden] { display: none; }
.portal legend { font-size: .85rem; font-weight: 600; color: var(--muted); padding: 0 4px; }
.portal label.check, .portal label.radio { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: .95rem; }
.portal label.check span { font-weight: 400; font-size: .88rem; }
.student-row[hidden] { display: none; }
.hp { position: absolute; left: -5000px; }
.search { display: flex; gap: 8px; margin-bottom: 16px; max-width: 420px; }
.editor-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.editor-bar .label { margin-right: auto; }
.cover { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cover .label { flex: 1 1 100%; }
.cover-preview { width: 200px; aspect-ratio: 16 / 9; border-radius: 10px; background: var(--tint); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: .85rem; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.copy-box { display: flex; gap: 8px; margin: 12px 0; }
.copy-box input { font-size: .85rem !important; }

.alert { padding: 12px 16px; border-radius: 10px; margin: 12px 0; }
.alert-error { background: #f6e0da; color: #8a2f1b; }
.alert-ok { background: #e3efd9; color: #2f5a1d; }

/* Modal & toast */
dialog#modal { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); }
dialog#modal::backdrop { background: rgba(21,17,13,.55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 1.5rem; }
#modal-body { padding: 20px 22px 24px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; background: var(--ink); color: var(--ivory); padding: 12px 20px; border-radius: 12px; font-size: .92rem; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px); pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #9b3a23; }

/* Sign-in pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: radial-gradient(circle at 20% 10%, var(--tint), var(--band) 70%); }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px; width: min(440px, 100%); box-shadow: var(--shadow); }
.auth-card.wide { width: min(720px, 100%); }
.auth-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 28px; }
.brand.dark .brand-mark { color: var(--heading); }
.auth-card h1 { margin-bottom: 8px; }
.btn-google { width: 100%; background: #fff; color: #1f1f1f; border: 1px solid #dadce0; gap: 10px; margin-top: 18px; }
.btn-google:hover { background: #f6f6f6; border-color: #c6c6c6; }
.btn-google svg { width: 20px; height: 20px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-info { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); font-size: .9rem; color: var(--muted); }
.auth-info a { color: var(--accent-text); font-weight: 700; }
.auth { align-content: center; gap: 18px; }
.auth-foot { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; font-size: .9rem; }
.auth-foot a { color: var(--muted); text-decoration: none; }
.auth-foot a:hover { color: var(--heading); text-decoration: underline; }
.auth-info strong { color: var(--text); }

/* Theme toggle & dark-mode tweaks */
.topbar .icon-toggle, .auth-top .icon-toggle { border-color: var(--line); color: var(--text); }
.auth-tools { display: flex; gap: 8px; align-items: center; }
:root[data-theme="dark"] .chip-active, :root[data-theme="dark"] .chip-done, :root[data-theme="dark"] .chip-reviewed, :root[data-theme="dark"] .chip-completed, :root[data-theme="dark"] .chip-published, :root[data-theme="dark"] .chip-paid { background: rgba(120,180,90,.18); color: #b5dc9c; }
:root[data-theme="dark"] .chip-pending, :root[data-theme="dark"] .chip-proposed, :root[data-theme="dark"] .chip-assigned, :root[data-theme="dark"] .chip-draft { background: rgba(226,189,124,.16); color: #e8c78e; }
:root[data-theme="dark"] .chip-scheduled, :root[data-theme="dark"] .chip-registered { background: rgba(110,160,220,.18); color: #a9c8ef; }
:root[data-theme="dark"] .chip-disabled, :root[data-theme="dark"] .chip-rejected, :root[data-theme="dark"] .chip-cancelled, :root[data-theme="dark"] .chip-withdrawn { background: rgba(217,115,94,.18); color: #f0a897; }
:root[data-theme="dark"] .alert-error { background: rgba(217,115,94,.18); color: #f0a897; }
:root[data-theme="dark"] .alert-ok { background: rgba(120,180,90,.18); color: #b5dc9c; }
.drop-hint { border: 2px dashed var(--accent); }
.hint a { color: var(--accent-text); }

/* Calendar */
:root { --ev-l: #c89b52; --ev-e: #4f7cc0; --ev-h: #4f9a5c; --ev-s: #9b6bc9; }
.ev-l { --c: var(--ev-l); } .ev-e { --c: var(--ev-e); } .ev-h { --c: var(--ev-h); } .ev-s { --c: var(--ev-s); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-nav .btn { min-width: 38px; }
.cal-title { margin: 0 0 0 10px; font-size: 1.6rem; text-transform: capitalize; }
.cal-views { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--surface); }
.cal-views a { padding: 6px 14px; border-radius: 999px; text-decoration: none; font-size: .88rem; font-weight: 600; color: var(--muted); }
.cal-views a.active { background: var(--heading); color: var(--bg); }
.cal-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 16px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.portal .cal-filters label.cal-type { flex-direction: row; align-items: center; gap: 7px; font-weight: 600; color: var(--text); font-size: .9rem; cursor: pointer; }
.cal-filters select { width: auto !important; padding: 7px 10px !important; font-size: .88rem !important; }
.cal-filters .check { font-size: .88rem !important; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-wd { background: var(--tint); padding: 8px 10px; font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cal-cell { background: var(--surface); min-height: 118px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-week .cal-cell { min-height: 380px; }
.cal-cell:hover { background: var(--bg); }
.cal-cell.other { background: var(--bg); }
.cal-cell.other .cal-num { opacity: .45; }
.cal-num { font-size: .85rem; font-weight: 600; color: var(--text); width: fit-content; min-width: 26px; height: 26px; padding: 0 6px; display: grid; place-items: center; border-radius: 999px; }
.cal-cell.is-today .cal-num { background: var(--accent); color: var(--on-accent); }
.cal-evs { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ev { display: flex; gap: 5px; align-items: baseline; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--c); border-radius: 5px; padding: 3px 6px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--text); font: inherit; font-size: .78rem; line-height: 1.3; cursor: pointer; min-width: 0; }
.ev:hover { background: color-mix(in srgb, var(--c) 28%, var(--surface)); }
.ev-time { font-weight: 700; flex: none; }
.ev-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-week .ev-title { white-space: normal; }
.ev-cancelled { opacity: .55; text-decoration: line-through; }
.cal-more { font-size: .75rem; font-weight: 700; color: var(--muted); padding: 0 6px; }

.cal-list { display: flex; flex-direction: column; gap: 10px; }
.cal-list-day { display: grid; grid-template-columns: 110px 1fr; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.cal-list-day.is-today { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.cal-list-date { display: flex; flex-direction: column; align-items: flex-start; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: var(--text); text-align: left; }
.cal-list-date strong { font-family: var(--serif); font-size: 2rem; line-height: 1; color: var(--heading); }
.cal-list-date span { font-size: .8rem; color: var(--muted); text-transform: capitalize; }
.cal-list-items { display: flex; flex-direction: column; gap: 6px; }
.cal-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: color-mix(in srgb, var(--c) 10%, var(--surface)); border: 0; border-left: 3px solid var(--c); border-radius: 8px; padding: 8px 12px; }
.cal-row:hover { background: color-mix(in srgb, var(--c) 20%, var(--surface)); }
.cal-row-time { font-size: .82rem; font-weight: 700; min-width: 96px; }
.cal-row-main { display: flex; flex-direction: column; min-width: 0; }
.cal-row-main small { color: var(--muted); }
.cal-when { display: flex; align-items: center; gap: 8px; font-weight: 600; text-transform: capitalize; }
.portal label.time-row[hidden] { display: none; }

@media (max-width: 700px) {
  .cal-title { font-size: 1.25rem; margin: 6px 0 0; flex-basis: 100%; }
  .cal-cell { min-height: 58px; padding: 4px; }
  .cal-week .cal-cell { min-height: 58px; }
  .cal-num { font-size: .78rem; min-width: 22px; height: 22px; }
  .cal-evs { flex-direction: row; flex-wrap: wrap; gap: 3px; }
  .ev { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 50%; background: var(--c); font-size: 0; }
  .ev-time, .ev-title { display: none; }
  .cal-more { display: none; }
  .cal-wd { padding: 6px 2px; text-align: center; font-size: .66rem; letter-spacing: 0; }
  .cal-list-day { grid-template-columns: 1fr; gap: 6px; }
  .cal-list-date { flex-direction: row; align-items: baseline; gap: 8px; }
  .cal-list-date strong { font-size: 1.5rem; }
}

/* Passwords */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 46px !important; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 8px; }
.pw-eye:hover, .pw-eye.on { color: var(--heading); background: var(--tint); }
.pw-eye svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pw-rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.pw-rules li { display: flex; align-items: center; gap: 8px; transition: color .2s; }
.pw-rules li::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: none; box-sizing: border-box; transition: all .2s; }
.pw-rules li.ok { color: #3c6b27; font-weight: 600; }
.pw-rules li.ok::before { background: #4f9a5c; border-color: #4f9a5c; box-shadow: inset 0 0 0 3px var(--surface); }
:root[data-theme="dark"] .pw-rules li.ok { color: #b5dc9c; }
.pw-card { max-width: 520px; }
.forgot-link { align-self: center; font-size: .9rem; }
