/* ClerkOS Callings — tokens + scoped styles. No framework. */
:root {
  --bg: #F4F6FA; --surface: #FFFFFF; --line: #DCE3EC; --text: #14213D; --muted: #6B7A90;
  --navy: #1E3A5F; --accent: #2F80ED; --accent-soft: #E3EEFC; --amber: #F2A33C; --green: #2E9E5B; --red: #D9534F; --purple: #7B61FF;
  --radius: 10px; --shadow: 0 8px 30px rgba(20,33,61,.12);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0F172A; --surface: #182235; --line: #2A3650; --text: #E6ECF5; --muted: #93A1B8; --accent-soft: #1C2F4D; --shadow: 0 8px 30px rgba(0,0,0,.5); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
small { color: var(--muted); font-size: .8em; }

/* header */
.app-header { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding: .6rem 1rem; display: grid; grid-template-columns: auto 1fr auto; gap: .75rem 1.25rem; align-items: center; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--navy); display: flex; align-items: center; gap: .5rem; }
.brand img { width: 26px; height: 26px; }
.brand span { color: var(--muted); font-weight: 500; }
@media (prefers-color-scheme: dark) { .brand { color: #fff; } }
.tabs { display: flex; gap: .25rem; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: .45rem .8rem; border-radius: 999px; cursor: pointer; }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab .count { font-weight: 500; opacity: .7; margin-left: .3rem; }
.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.filters select, .filters input { font: inherit; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.filters input[type=search] { min-width: 200px; }
.who { font-size: .8rem; color: var(--muted); white-space: nowrap; }

.btn { font: inherit; font-weight: 600; padding: .45rem .8rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.icon { padding: .3rem .5rem; line-height: 1; }
.btn:hover { filter: brightness(.97); }
details.menu { position: relative; }
details.menu summary { list-style: none; cursor: pointer; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu .menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; min-width: 220px; padding: .3rem; z-index: 10; }
details.menu .menu-list button { text-align: left; border: 0; background: transparent; font: inherit; padding: .5rem .7rem; border-radius: 6px; cursor: pointer; color: var(--text); }
details.menu .menu-list button:hover { background: var(--accent-soft); }

/* table */
#main { padding: 1rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.callings { border-collapse: collapse; width: 100%; min-width: 980px; }
.callings th { text-align: left; font-size: .7rem; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); padding: .55rem .4rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.callings td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.callings tr { cursor: pointer; }
.callings tbody tr:hover { background: var(--accent-soft); }
.callings tr.open { outline: 2px solid var(--accent); outline-offset: -2px; }
.callings td.unit { font-weight: 700; color: var(--navy); white-space: nowrap; }
@media (prefers-color-scheme: dark) { .callings td.unit { color: #fff; } }
.callings td.title { min-width: 220px; font-weight: 600; }
.callings td.names { min-width: 160px; }
.cand { display: inline-block; margin: 0 .35rem .2rem 0; padding: .05rem .45rem; border-radius: 6px; background: var(--accent-soft); font-size: .9em; }
.cand.s-declined { text-decoration: line-through; opacity: .6; }
.cand.s-hold { background: #FDEFD5; color: #8A5A00; }
.cand.s-accepted { background: #E2F5E9; color: #1E6B3C; }
.callings td.days { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip { font: inherit; font-size: .76rem; font-weight: 700; min-width: 40px; padding: .15rem .35rem; border-radius: 999px; border: 1px dashed var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.chip.v-yes { background: #E2F5E9; color: #1E6B3C; border: 1px solid transparent; }
.chip.v-na { background: #EEF1F6; color: var(--muted); border: 1px solid transparent; }
.chip.v-hold { background: #FDEFD5; color: #8A5A00; border: 1px solid transparent; }
.chip.v-pause { background: #EDE8FF; color: #4B34B8; border: 1px solid transparent; }
@media (prefers-color-scheme: dark) { .chip.v-yes { background: #16402A; color: #8BE0A8; } .chip.v-na { background: #263148; color: #AAB6CA; } .chip.v-hold { background: #4A3410; color: #F6C77A; } .chip.v-pause { background: #2C2560; color: #C3B6FF; } .cand.s-accepted { background: #16402A; color: #8BE0A8; } .cand.s-hold { background: #4A3410; color: #F6C77A; } }
.next { display: inline-block; font-size: .78rem; font-weight: 700; padding: .15rem .55rem; border-radius: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.next.names { background: #FDEFD5; color: #8A5A00; }
.next.hold { background: #EEF1F6; color: var(--muted); }
.next.lcr { background: #EDE8FF; color: #4B34B8; }
.next.complete { background: #E2F5E9; color: #1E6B3C; }
#empty { padding: 3rem; text-align: center; color: var(--muted); }

/* drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 20; overflow-y: auto; padding: 1rem 1.25rem 2rem; display: flex; flex-direction: column; gap: 1rem; }
.drawer header { display: flex; gap: .5rem; align-items: center; }
.drawer header input { flex: 1; font: inherit; font-size: 1.1rem; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: .3rem .5rem; background: transparent; color: var(--text); }
.drawer header input:hover, .drawer header input:focus { border-color: var(--line); background: var(--bg); }
.drawer .grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .8rem; }
.drawer label { display: grid; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 600; }
.drawer label input, .drawer label select, .drawer textarea { font: inherit; font-size: .95rem; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; }
.drawer .steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.drawer .step { display: grid; gap: .25rem; font-size: .75rem; color: var(--muted); font-weight: 600; }
.drawer h3 { margin: 0 0 .4rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.drawer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.drawer .cands li { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 8px; }
.drawer .cands li.unlinked { border-style: dashed; }
.drawer .cand-main { display: grid; gap: .1rem; min-width: 0; }
.drawer .cand-name { font-weight: 600; }
.drawer .cand-main small { line-height: 1.3; }
.drawer .cand-link { font-size: .75rem; padding: .1rem .4rem; margin-left: .3rem; }
.cand.unlinked { background: transparent; border: 1px dashed var(--muted); }
.typeahead { position: relative; flex-wrap: wrap; }
.typeahead .suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); display: grid; max-height: 260px; overflow-y: auto; }
.typeahead .suggest button { text-align: left; font: inherit; font-size: .9rem; padding: .45rem .7rem; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.typeahead .suggest button:hover { background: var(--accent-soft); }
.drawer .cands select { font: inherit; font-size: .85rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); padding: .2rem .3rem; }
.drawer form { display: flex; gap: .5rem; margin-top: .5rem; }
.drawer form input, .drawer form textarea { flex: 1; }
.drawer .notes li { position: relative; padding: .5rem .6rem 0.5rem; border-left: 3px solid var(--accent-soft); background: var(--bg); border-radius: 0 8px 8px 0; padding-right: 2.2rem; }
.drawer .notes li small { display: block; margin-top: .2rem; }
.drawer .notes .note-del { position: absolute; right: .3rem; top: .3rem; opacity: .5; }
.drawer .plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.drawer footer { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* sign-in */
a.btn { text-decoration: none; display: inline-block; text-align: center; }
#handoff, #signin { max-width: 380px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); display: grid; gap: .8rem; text-align: center; }
#signin h1 { margin: 0; font-size: 1.3rem; }
#signin form { display: grid; gap: .6rem; }
#signin input { font: inherit; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
#not-allowed { margin: 1rem 0; padding: .8rem 1rem; border-radius: 8px; background: #FDEFD5; color: #8A5A00; }

#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--navy); color: #fff; padding: .6rem 1rem; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; transition: opacity .3s; opacity: 0; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 800px) {
  .app-header { grid-template-columns: 1fr; }
  .filters { justify-content: flex-start; }
  .drawer .steps { grid-template-columns: repeat(2, 1fr); }
}
