:root {
  --bg: #0f1020;
  --bg-2: #171832;
  --card: #1d1f3a;
  --card-2: #23264a;
  --text: #eceefc;
  --muted: #9aa0c9;
  --accent: #6f6bf5;
  --accent-2: #8f8bff;
  --danger: #ff5d6c;
  --ok: #38d39f;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #26265a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  min-height: 100vh;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 13px;
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), #b06bff);
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- Views ---------- */
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 14px; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }

/* ---------- Cards & forms ---------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid rgba(255,255,255,.06);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.form { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; }
.row > input { flex: 1 1 auto; min-width: 0; }

input, textarea, button, select { font: inherit; color: var(--text); }

select.sel {
  width: 100%; background: #12142c;
  border: 1px solid rgba(255,255,255,.09); border-radius: 12px;
  padding: 12px 13px; outline: none;
}
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: rgba(255,255,255,.08); color: var(--muted); }
.badge.p1 { background: rgba(154,160,201,.18); color: #c8cce6; }
.badge.p2 { background: rgba(111,107,245,.20); color: #c3c1ff; }
.badge.p3 { background: rgba(255,180,84,.18); color: #ffd59b; }
.badge.p4 { background: rgba(255,93,108,.18); color: #ffb3ba; }

input[type="text"], input[type="password"], input[type="datetime-local"], textarea {
  width: 100%;
  background: #12142c;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
  resize: vertical;
}
input:focus, textarea:focus { border-color: var(--accent); }

button { cursor: pointer; border: 0; border-radius: 12px; transition: transform .05s ease, filter .15s ease; }
button:active { transform: scale(.98); }

.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); padding: 12px 14px; font-weight: 700; }
.ghost { background: rgba(255,255,255,.07); padding: 10px 14px; font-weight: 600; }
.ghost.round { width: 38px; height: 38px; padding: 0; font-size: 22px; line-height: 1; }
.ghost.round.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.ghost.wide, .danger.wide { width: 100%; }
.row.wrap { flex-wrap: wrap; }
.row.wrap .ghost { padding: 6px 10px; font-size: 12.5px; }
.danger { background: rgba(255,93,108,.14); color: #ffb3ba; padding: 12px 14px; font-weight: 700; }
.hidden { display: none !important; }

/* ---------- Экран входа ---------- */
.auth {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 520px at 50% 0%, #26265a 0%, var(--bg) 60%);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.auth-logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 800; font-size: 18px;
}
.auth-title { margin: 0; font-size: 20px; }
.auth-sub { margin: 0; color: var(--muted); font-size: 14px; }
.auth-error { color: var(--danger); font-size: 13px; margin: 0; }
.auth-hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; line-height: 1.35; }
.auth-hint code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 5px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.item {
  background: var(--card);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px;
  padding: 12px 13px;
  display: flex; align-items: flex-start; gap: 10px;
}
.item .grow { flex: 1 1 auto; min-width: 0; }
.item .txt { white-space: pre-wrap; word-break: break-word; }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.item.done .txt { text-decoration: line-through; color: var(--muted); }
.item .del { background: transparent; color: var(--muted); font-size: 18px; padding: 2px 6px; }
.item .check {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px; margin-top: 2px;
  border: 2px solid rgba(255,255,255,.25); background: transparent;
}
.item.done .check { background: var(--ok); border-color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

/* ---------- Теги заметок ---------- */
.tagbar { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 2px 0; }
.tagbar:empty { display: none; }
.tag {
  background: rgba(255,255,255,.06); color: var(--muted); border: 1px solid transparent;
  border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tag.on { background: rgba(111,107,245,.25); color: #cfcdff; border-color: var(--accent); }
.tag.mini { padding: 1px 8px; font-size: 11px; cursor: default; background: rgba(111,107,245,.16); color: #c3c1ff; }
a.btn-link { display: block; text-align: center; text-decoration: none; margin-top: 0; color: var(--text); box-sizing: border-box; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid .dow { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-day {
  aspect-ratio: 1 / 1; border-radius: 11px; display: grid; place-items: center;
  background: rgba(255,255,255,.04); font-size: 14px; position: relative;
  border: 1px solid transparent;
}
.cal-day.out { opacity: .35; }
.cal-day.today { border-color: var(--accent-2); font-weight: 800; }
.cal-day.sel { background: var(--accent); }
.cal-day.has::after {
  content: ""; position: absolute; bottom: 6px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--ok);
}

.hint { font-size: 12px; color: var(--muted); margin: 12px 2px 0; }

/* ---------- Mic & tabbar ---------- */
.mic {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; font-size: 24px;
  background: linear-gradient(135deg, var(--accent), #b06bff);
  box-shadow: 0 10px 26px rgba(111,107,245,.5);
  z-index: 20;
}
.mic.listening { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 10px 26px rgba(111,107,245,.5); } 50% { box-shadow: 0 0 0 14px rgba(111,107,245,.18); } }
button.listening { animation: pulse 1.1s infinite; color: var(--accent); }

.field.row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.chk { width: 20px; height: 20px; accent-color: var(--accent); }
.sep { border: 0; border-top: 1px solid rgba(255,255,255,.10); margin: 8px 0 2px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: rgba(15,16,32,.88);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,.07);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1 1 0; max-width: 120px; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 18px; padding: 6px 2px; border-radius: 12px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--text); background: rgba(255,255,255,.06); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(146px + env(safe-area-inset-bottom));
  background: #2a2d52; border: 1px solid rgba(255,255,255,.1);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 30; max-width: 90vw; text-align: center;
}

/* ---------- Планировщик ---------- */
.quad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quad {
  border-radius: 13px; padding: 12px; border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
}
.quad .q-title { font-size: 13px; font-weight: 700; }
.quad .q-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.quad .q-count { font-size: 24px; font-weight: 800; margin-top: 6px; }
.quad.q1 { background: rgba(255,93,108,.12); } .quad.q1 .q-title { color: #ffb3ba; }
.quad.q2 { background: rgba(111,107,245,.14); } .quad.q2 .q-title { color: #c3c1ff; }
.quad.q3 { background: rgba(255,180,84,.12); } .quad.q3 .q-title { color: #ffd59b; }
.quad.q4 { background: rgba(154,160,201,.10); } .quad.q4 .q-title { color: #c8cce6; }

.slot {
  background: var(--card); border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px; padding: 12px 13px; margin-bottom: 10px;
}
.slot-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.slot-head .slot-name { font-weight: 700; }
.slot-head .slot-cap { font-size: 12px; color: var(--muted); }
.slot.overload .slot-head .slot-cap { color: var(--danger); }
.slot .task-line { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 3px 0; }
.slot .task-line .dur { color: var(--muted); font-size: 12px; }
.slot .empty-line { color: var(--muted); font-size: 13px; }

.badge.q1 { background: rgba(255,93,108,.18); color: #ffb3ba; }
.badge.q2 { background: rgba(111,107,245,.20); color: #c3c1ff; }
.badge.q3 { background: rgba(255,180,84,.18); color: #ffd59b; }
.badge.q4 { background: rgba(154,160,201,.18); color: #c8cce6; }

.leftover {
  margin-top: 10px; padding: 12px 13px; border-radius: 14px;
  background: rgba(255,93,108,.10); border: 1px solid rgba(255,93,108,.35);
  font-size: 13px;
}

/* ---------- Планировщик: неделя и календарные окна ---------- */
.seg-row { gap: 8px; }
.seg-btn { flex: 1 1 0; padding: 8px 10px; }
.seg-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.plan-actions { margin-top: 10px; flex-wrap: wrap; }
.plan-actions .ghost { flex: 1 1 auto; }

.ev-card { margin-bottom: 10px; }
.ev-card .task-line span:first-child { font-weight: 600; }

.unsched {
  margin-top: 10px; padding: 10px 13px; border-radius: 14px; font-size: 13px;
  background: rgba(143,139,255,.10); border: 1px solid rgba(143,139,255,.35); color: #c3c1ff;
}

.wday {
  background: var(--card); border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px; padding: 11px 12px; margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.wday:hover { border-color: rgba(143,139,255,.5); }
.wday.today { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(111,107,245,.35); }
.wday.over { background: rgba(255,93,108,.08); border-color: rgba(255,93,108,.4); }
.wday-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.wday-name { font-weight: 600; }
.wday-name b { color: var(--accent-2); }
.wday-load { font-size: 12px; color: var(--muted); }
.wday.over .wday-load { color: var(--danger); }
.loadbar { height: 6px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; margin-bottom: 8px; }
.loadbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.wday.over .loadbar i { background: linear-gradient(90deg, #ff8a5d, var(--danger)); }
.wev, .wtask { font-size: 13px; padding: 2px 0; display: flex; justify-content: space-between; gap: 8px; }
.wev { color: #ffd59b; }
.wtask { color: var(--text); }
.wev span, .wtask span { color: var(--muted); font-size: 12px; }
.wday .empty-line { color: var(--muted); font-size: 13px; }

/* ---------- Навыки: реестр и конструктор ---------- */
.skills { margin-top: 10px; }
.skill {
  background: var(--card-2); border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.skill-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.sk-badge { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: rgba(255,255,255,.08); color: var(--muted); white-space: nowrap; }
.sk-badge.active { background: rgba(56,211,159,.16); color: #8ff0cb; }
.sk-badge.draft { background: rgba(255,180,84,.16); color: #ffd59b; }
.sk-badge.disabled { background: rgba(154,160,201,.16); color: #c8cce6; }
.skill-meta { font-size: 12.5px; color: var(--muted); margin: 3px 0; }
.chip { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 8px;
        background: rgba(143,139,255,.16); color: #c3c1ff; margin: 1px 2px; }
.skill-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.skill-actions .primary, .skill-actions .ghost { flex: 1 1 auto; }
.skill-builtins { font-size: 12px; color: var(--muted); margin-top: 10px; }
.skill-preview-box {
  background: rgba(143,139,255,.10); border: 1px solid rgba(143,139,255,.35);
  border-radius: 12px; padding: 10px 12px; margin-top: 10px;
}
.verchip {
  font-size: 11px; padding: 1px 7px; margin: 1px 2px; border-radius: 8px; cursor: pointer;
  background: rgba(255,255,255,.08); color: var(--muted); border: 1px solid rgba(255,255,255,.12);
}
.verchip.cur { background: rgba(111,107,245,.35); color: #fff; border-color: transparent; }

/* ---------- Чат с агентом ---------- */
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: min(680px, 100vw);
  max-height: 78vh; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid rgba(255,255,255,.10);
  border-radius: 20px 20px 0 0; box-shadow: 0 -14px 50px rgba(0,0,0,.55);
  z-index: 40; padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head strong { flex: 1 1 auto; }
.agent-log { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 0; min-height: 120px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid rgba(255,255,255,.07); border-bottom-left-radius: 5px; }
.sheet-form { display: flex; gap: 8px; margin-top: 10px; }
.sheet-form input { flex: 1 1 auto; }
