:root {
  --bg: #121014;
  --panel: #1b181e;
  --panel-2: #241f28;
  --line: #322b37;
  --text: #f3eef5;
  --muted: #9a90a1;
  --accent: #ff6b4a;
  --accent-ink: #1a0d08;
  --ok: #3ec7a6;
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --display: 'Space Grotesk', var(--font);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-width: 0; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
input[type=date], input[type=time] { color-scheme: dark; }

.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; white-space: nowrap; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--text); }
.ghost:hover { background: var(--panel-2); }
.small { padding: 6px 10px; font-size: 13px; }
.icon { background: none; border: 0; color: var(--muted); padding: 4px 6px; border-radius: 6px; line-height: 1; }
.icon:hover { color: var(--text); background: var(--panel-2); }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 10px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; }

.brand { font: 700 22px/1 var(--display); letter-spacing: -0.02em; margin: 0; }
.brand span { color: var(--accent); }
.brand.big { font-size: 44px; }

/* ---------- Gate & picker ---------- */
.screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.gate-card, .picker-card { text-align: center; width: 100%; max-width: 340px; }
.gate-card .muted { margin: 10px 0 22px; }
.dots { display: flex; justify-content: center; gap: 16px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); transition: .15s; }
.dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.gate-msg { min-height: 22px; color: var(--accent); font-size: 14px; margin: 14px 0; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button { aspect-ratio: 1.4; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); font: 500 24px var(--display); }
.keypad button:active { background: var(--panel-2); transform: scale(.97); }

.people { display: grid; gap: 12px; margin: 22px 0 8px; }
.person { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); text-align: left; font-size: 17px; font-weight: 500; }
.person:hover { border-color: var(--c); }
.person.edit { cursor: default; }
.person.edit input[type=text] { flex: 1; }
.person.edit input[type=color] { width: 42px; height: 38px; padding: 2px; flex: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font: 700 16px var(--display); background: var(--c); color: #120f12; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }

/* ---------- App shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 18px; padding: 14px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); z-index: 5; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; white-space: nowrap; position: relative; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; line-height: 18px; margin-left: 4px; }
.me { display: flex; gap: 8px; align-items: center; }
.me-chip { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; }
main { flex: 1; padding: 20px; width: 100%; max-width: 1200px; margin: 0 auto; }
.tab { animation: fade .2s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Board ---------- */
.bar { display: grid; grid-template-columns: 1fr 160px 160px auto; gap: 8px; margin-bottom: 18px; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 140px; }
.col h3 { margin: 2px 4px 12px; font: 600 13px var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; margin-bottom: 8px; border-left: 3px solid var(--c, var(--line)); }
.card .t { font-weight: 500; cursor: text; word-break: break-word; }
.card.done .t { text-decoration: line-through; color: var(--muted); }
.card .meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.card .meta select { width: auto; padding: 3px 6px; font-size: 12px; border-radius: 7px; }
.card .meta .due.late { color: var(--accent); }
.card .acts { margin-left: auto; display: flex; gap: 2px; }
.card input.t-edit { padding: 4px 6px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 6px; }

/* ---------- Chat ---------- */
#tab-chat { display: flex; flex-direction: column; height: calc(100dvh - 110px); }
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 12px; }
.msg { max-width: min(560px, 82%); display: flex; gap: 8px; align-items: flex-end; }
.msg .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 8px 12px; white-space: pre-wrap; word-break: break-word; }
.msg .who { font-size: 12px; color: var(--c); font-weight: 600; margin-bottom: 2px; }
.msg .when { font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .bubble { background: color-mix(in srgb, var(--c) 22%, var(--panel)); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); border-radius: 16px 16px 4px 16px; }
.msg .icon { opacity: 0; }
.msg:hover .icon { opacity: 1; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.chat-form { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-form textarea { resize: none; max-height: 140px; }

/* ---------- Notes ---------- */
.note-form { display: grid; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.note-form.editing { border-color: var(--accent); }
.notes { columns: 3 280px; column-gap: 14px; }
.note { break-inside: avoid; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.note.pinned { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.note h4 { margin: 0 0 6px; font: 600 16px var(--display); display: flex; gap: 8px; align-items: start; }
.note h4 span { flex: 1; word-break: break-word; }
.note p { margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; color: #ddd4e2; }
.note a { color: var(--ok); word-break: break-all; font-size: 13px; }
.note .foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.note .foot .acts { margin-left: auto; }
.pin.on { color: var(--accent); }

/* ---------- Calendar ---------- */
.cal-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.cal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; font: 600 18px var(--display); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { font-size: 11px; color: var(--muted); text-align: center; padding: 4px 0; text-transform: uppercase; letter-spacing: .06em; }
.day { min-height: 86px; background: var(--panel-2); border: 1px solid transparent; border-radius: 9px; padding: 5px; cursor: pointer; overflow: hidden; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.day:hover { border-color: var(--line); }
.day.other { opacity: .35; }
.day.today .n { background: var(--accent); color: var(--accent-ink); }
.day.sel { border-color: var(--accent); }
.day .n { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.day .ev { font-size: 11px; padding: 1px 5px; border-radius: 5px; background: color-mix(in srgb, var(--c, var(--muted)) 28%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.cal-side h3 { font: 600 13px var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.event-form { display: grid; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.up { display: flex; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.up .d { width: 44px; text-align: center; flex: none; background: var(--panel); border-radius: 9px; padding: 4px 0; border-top: 3px solid var(--c, var(--line)); }
.up .d b { display: block; font: 700 18px var(--display); }
.up .d small { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.up .info { flex: 1; min-width: 0; }
.up .info .t { font-weight: 500; word-break: break-word; }
.up .info .s { font-size: 12px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 90vw; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .top { flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  main { padding: 16px; }
  .bar { grid-template-columns: 1fr 1fr; }
  .bar input[name=title] { grid-column: 1 / -1; }
  .bar button { grid-column: 1 / -1; }
  .board { grid-template-columns: 1fr; }
  .cal-wrap { grid-template-columns: 1fr; }
  .day { min-height: 54px; }
  .day .ev { font-size: 0; height: 6px; padding: 0; }
  #tab-chat { height: calc(100dvh - 150px); }
  .msg .icon { opacity: 1; }
}
