/* ============================================================
   assets/css/app.css — SCAL
   No build step. Tokens on :root; dark mode via prefers-color-scheme.
   ============================================================ */

:root {
    --brand:        #1f3a6b;
    --brand-600:    #2a4d8c;
    --brand-50:     #eef3fb;
    --accent:       #c8102e;
    --bg:           #f4f6fa;
    --surface:      #ffffff;
    --surface-2:    #f8f9fc;
    --border:       #e2e6ee;
    --text:         #1d2433;
    --text-muted:   #5d6679;
    --text-faint:   #8a92a3;
    --success:      #1e7d4f;
    --success-bg:   #e6f4ec;
    --warn:         #9a6200;
    --warn-bg:      #fff4dc;
    --danger:       #b42318;
    --danger-bg:    #fdecea;
    --radius:       10px;
    --radius-sm:    6px;
    --shadow:       0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
    --shadow-lg:    0 12px 32px rgba(16,24,40,.16);
    --sidebar-w:    232px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand:      #8fb0ec;
        --brand-600:  #a9c3f2;
        --brand-50:   #1c2840;
        --accent:     #ff5a6e;
        --bg:         #0f131b;
        --surface:    #171c26;
        --surface-2:  #1d2330;
        --border:     #2a3242;
        --text:       #e6e9ef;
        --text-muted: #a3abbb;
        --text-faint: #6f7889;
        --success:    #5fd29a;
        --success-bg: #11291d;
        --warn:       #f2bd54;
        --warn-bg:    #2d2412;
        --danger:     #ff7a6e;
        --danger-bg:  #33171a;
        --shadow:     0 1px 2px rgba(0,0,0,.4);
        --shadow-lg:  0 12px 32px rgba(0,0,0,.5);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 620; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- App shell -------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .org {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border);
}
.sidebar .org-name { font-weight: 650; font-size: .98rem; line-height: 1.3; }
.sidebar .org-app { font-size: .75rem; color: var(--text-faint); letter-spacing: .04em; text-transform: uppercase; }
.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-50); color: var(--brand); }
.sidebar nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav .section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 14px 12px 4px; }
.sidebar .badge { margin-left: auto; }
.sidebar .me {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    display: flex; align-items: center; gap: 10px;
}
.sidebar .me .who { flex: 1; min-width: 0; }
.sidebar .me .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; min-width: 0; }
.topbar { display: none; }
.content { max-width: 1180px; margin: 0 auto; padding: 28px 28px 60px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (max-width: 860px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 50;
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .scrim { display: block; }
    .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
    .topbar {
        display: flex; align-items: center; gap: 12px;
        padding: 10px 16px; background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky; top: 0; z-index: 30;
    }
    .topbar .title { font-weight: 620; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .content { padding: 18px 16px 48px; }
}

/* ---- Components ------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 1rem; }
.card-body { padding: 16px 20px; }
.card + .card { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 960px) { .grid-2, .grid-3, .grid-main { grid-template-columns: 1fr; } }

.stat { padding: 16px 20px; }
.stat .n { font-size: 1.7rem; font-weight: 650; line-height: 1.1; }
.stat .l { color: var(--text-muted); font-size: .85rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 550; font-size: .92rem; cursor: pointer; white-space: nowrap;
    min-height: 36px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--brand-600); outline-offset: 1px;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0f131b; } }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .84rem; min-height: 30px; }
.btn-link { background: none; border: none; padding: 0; color: var(--brand-600); cursor: pointer; font: inherit; min-height: 0; }
.btn svg { width: 16px; height: 16px; }
form.inline { display: inline; }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 999px;
    font-size: .74rem; font-weight: 600; line-height: 1.5;
    background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge-brand  { background: var(--brand-50); color: var(--brand); border-color: transparent; }
.badge-ok     { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-warn   { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge-live   { background: var(--accent); color: #fff; border-color: transparent; }
.badge-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--brand-50); color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 650; flex-shrink: 0;
}

.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error   { background: var(--danger-bg); color: var(--danger); }
.flash-info    { background: var(--brand-50); color: var(--brand); }
.errors { background: var(--danger-bg); color: var(--danger); padding: 10px 14px 10px 32px; border-radius: var(--radius-sm); margin: 0 0 16px; }

/* ---- Lists ------------------------------------------------ */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 20px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.list > li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 560; color: var(--text); }
.list a.t:hover { color: var(--brand-600); }
.list .meta { color: var(--text-muted); font-size: .84rem; }
.empty { padding: 28px 20px; text-align: center; color: var(--text-muted); }
.empty svg { width: 32px; height: 32px; color: var(--text-faint); display: block; margin: 0 auto 8px; }

.datebox {
    width: 46px; flex-shrink: 0; text-align: center; border-radius: var(--radius-sm);
    border: 1px solid var(--border); overflow: hidden; background: var(--surface);
}
.datebox .m { background: var(--brand); color: #fff; font-size: .66rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; padding: 1px 0; }
@media (prefers-color-scheme: dark) { .datebox .m { color: #0f131b; } }
.datebox .d { font-size: 1.1rem; font-weight: 650; padding: 2px 0; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---- Forms ------------------------------------------------ */
.form { max-width: 720px; }
.field { margin-bottom: 16px; }
.field label, .label { display: block; font-weight: 560; margin-bottom: 5px; font-size: .92rem; }
.field .hint { color: var(--text-muted); font-size: .82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search],
input[type=date], input[type=datetime-local], input[type=number], select, textarea {
    width: 100%; padding: 8px 11px; font: inherit; font-size: .95rem;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    min-height: 38px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.tall { min-height: 360px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 450; margin-bottom: 8px; }
.check input { margin-top: 4px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.picklist { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface); }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.searchbar input[type=search] { max-width: 280px; }

/* ---- Rendered text (notes, descriptions) ----------------- */
.prose { overflow-wrap: anywhere; }
.prose p { margin: 0 0 .4rem; }
.prose ul { margin: .25rem 0 .6rem; padding-left: 1.3rem; }
.prose h3, .prose h4, .prose h5 { margin: .9rem 0 .35rem; }

/* ---- Calendar --------------------------------------------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h2 { margin: 0; min-width: 180px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal .dow { font-size: .74rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); padding: 6px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal .day { min-height: 108px; padding: 4px 6px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); position: relative; }
.cal .day.other { background: var(--surface-2); }
.cal .day.other .num { color: var(--text-faint); }
.cal .num { font-size: .82rem; font-weight: 600; display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-muted); }
.cal .day.today .num { background: var(--brand); color: #fff; }
.cal .add { position: absolute; top: 4px; right: 6px; opacity: 0; font-size: 1.1rem; line-height: 1; color: var(--text-faint); }
.cal .day:hover .add { opacity: 1; }
.cal .ev {
    display: block; font-size: .78rem; padding: 2px 6px; border-radius: 4px; margin-top: 2px;
    background: var(--brand-50); color: var(--brand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal .ev:hover { text-decoration: none; filter: brightness(.97); }
.cal .ev.has-meeting { border-left: 3px solid var(--accent); }
.cal .ev.declined { opacity: .5; text-decoration: line-through; }
@media (max-width: 700px) {
    .cal .day { min-height: 64px; padding: 2px; }
    .cal .ev { font-size: 0; height: 6px; padding: 0; margin: 2px 1px 0; }
    .cal .dow { font-size: .66rem; padding: 4px 2px; text-align: center; }
}

/* ---- Task board ------------------------------------------- */
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 900px) { .board { grid-template-columns: 1fr; } }
.board .col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board .col.drop { outline: 2px dashed var(--brand-600); outline-offset: -4px; }
.board .col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 620; }
.tcard {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab;
}
.tcard.dragging { opacity: .5; }
.tcard .tt { font-weight: 560; color: var(--text); display: block; margin-bottom: 6px; }
.tcard .tm { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: .8rem; color: var(--text-muted); }
.prio-high { color: var(--danger); font-weight: 600; }
.overdue { color: var(--danger); font-weight: 600; }

/* ---- Public (auth) pages ---------------------------------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card-pad { padding: 28px; }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .org { font-size: 1.25rem; font-weight: 650; }
.auth-brand .app { font-size: .78rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; }
.auth-foot { text-align: center; margin-top: 16px; font-size: .9rem; }
.btn-block { width: 100%; }
.hp { position: absolute; left: -9999px; }

/* ---- Meeting detail --------------------------------------- */
.join-panel { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.join-panel .when { font-size: 1.05rem; font-weight: 560; }
