/* Calender — dark theme, no framework. */

:root {
  --bg: #0e1116;
  --surface: #161a22;
  --surface-2: #1c222d;
  --surface-3: #232a37;
  --border: #262d3a;
  --border-strong: #34405a;
  --text: #e6e9ef;
  --muted: #8b93a5;
  --faint: #5c6478;
  --accent: #7aa2f7;
  --accent-strong: #5b7fc4;
  --accent-soft: rgba(122, 162, 247, 0.16);
  --danger: #f7768e;
  --danger-soft: rgba(247, 118, 142, 0.16);
  --success: #9ece6a;
  --warning: #e0af68;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 9px;
  --nav-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { overflow-x: hidden; }

[hidden] { display: none !important; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--accent); }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
  line-height: 1.2;
  min-height: 38px;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b1020; font-weight: 600; }
.btn-primary:hover { background: #8fb2ff; border-color: #8fb2ff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 0.85rem; }
.btn-icon { padding: 6px; width: 36px; height: 36px; min-height: 0; border-radius: 50%; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-icon svg { width: 18px; height: 18px; }

/* ── forms ───────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 42px;
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[type="color"] { padding: 4px; height: 42px; width: 64px; cursor: pointer; }
.field input[type="date"], .field input[type="time"] { min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: 0.9rem; margin: 0 0 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }

/* ── layout ──────────────────────────────────────────────────────────────── */

.centered {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-title { font-size: 1.6rem; margin-bottom: 4px; display: flex; align-items: center; gap: 10px; }
.auth-subtitle { margin: 0 0 20px; color: var(--muted); }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none;
  display: inline-grid; place-items: center; color: #0b1020;
}
.logo svg { width: 18px; height: 18px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--nav-h);
  padding: 0 16px;
  background: rgba(14, 17, 22, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.tabs { display: flex; gap: 2px; margin-left: 12px; }
.tab {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.topbar .grow { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 6px 4px 12px; height: 38px; width: 260px;
}
.search input { flex: 1 1 0; width: 0; min-width: 0; background: none; border: 0; outline: none; color: var(--text); }
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu button {
  display: flex; width: 100%; align-items: center; gap: 10px;
  padding: 9px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left;
}
.menu button:hover { background: var(--surface-2); }
.menu .menu-head { padding: 8px 10px 6px; font-size: 0.8rem; color: var(--muted); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.main { padding: 16px; max-width: 1400px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-bottom)); }

.view-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.view-head h2 { font-size: 1.35rem; min-width: 200px; }
.view-head .nav { display: flex; gap: 4px; align-items: center; }
.view-head .grow { flex: 1; }
.subtle-badge {
  font-size: 0.78rem; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px;
}
.subtle-badge.warn { color: var(--warning); border-color: rgba(224, 175, 104, 0.4); }

/* ── month grid ──────────────────────────────────────────────────────────── */

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.month-grid .dow {
  background: var(--surface);
  padding: 8px 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.month-grid .dow.weekend { color: var(--faint); }
.day-cell {
  background: var(--bg);
  min-height: 112px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.15s;
  text-align: left;
  border: 0;
  color: inherit;
  overflow: hidden;
}
.day-cell:hover { background: var(--surface); }
.day-cell.other { color: var(--faint); background: #0b0e13; }
.day-cell.other .chip { opacity: 0.55; }
.day-cell.weekend { background: #0c0f15; }
.day-cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.day-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-size: 0.9rem; font-weight: 500;
}
.day-cell.today .day-num { background: var(--accent); color: #0b1020; font-weight: 700; }
.day-head { display: flex; align-items: center; justify-content: space-between; }
.task-dots { display: flex; gap: 3px; align-items: center; }
.task-count {
  font-size: 0.72rem; color: var(--muted); background: var(--surface-2);
  border-radius: 999px; padding: 1px 6px; border: 1px solid var(--border);
}
.task-count.carried { color: var(--warning); border-color: rgba(224, 175, 104, 0.4); }
.chip {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.76rem; line-height: 1.25;
  padding: 2px 6px; border-radius: 5px;
  background: color-mix(in srgb, var(--c, var(--accent)) 22%, transparent);
  border-left: 3px solid var(--c, var(--accent));
  color: var(--text);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  cursor: pointer;
}
.chip:hover { background: color-mix(in srgb, var(--c, var(--accent)) 38%, transparent); }
.chip .t { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.chip .title { overflow: hidden; text-overflow: ellipsis; }
.chip.more { background: none; border-left-color: transparent; color: var(--muted); padding-left: 3px; }

/* ── day panel ───────────────────────────────────────────────────────────── */

.month-layout { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1100px) {
  .month-layout.with-panel { grid-template-columns: 1fr 340px; }
}
.day-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; align-self: start; position: sticky; top: calc(var(--nav-h) + 16px);
}
.day-panel .panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.day-panel .panel-head h3 { font-size: 1.1rem; }
.day-panel .panel-head .close { margin-left: auto; }
.section-title {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  margin: 14px 0 6px; display: flex; align-items: center; gap: 8px;
}
.section-title .grow { flex: 1; }
.empty { color: var(--faint); font-size: 0.9rem; padding: 6px 0; }

/* ── lists of appointments / tasks ───────────────────────────────────────── */

.appt {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--border); border-left: 3px solid var(--c, var(--accent));
  cursor: pointer; margin-bottom: 6px;
}
.appt:hover { background: var(--surface-3); }
.appt .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; min-width: 42px; flex: none; padding-top: 1px; }
.appt .body { flex: 1; min-width: 0; }
.appt .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt .meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.appt .cat { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--accent)); display: inline-block; flex: none; }

.task {
  display: flex; align-items: flex-start; gap: 10px; padding: 7px 8px;
  border-radius: var(--radius-sm); margin-bottom: 4px;
  border: 1px solid transparent;
  cursor: grab;
  transition: background 0.12s;
}
.task:hover { background: var(--surface-2); border-color: var(--border); }
.task.dragging { opacity: 0.4; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .check {
  appearance: none; -webkit-appearance: none;
  width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--faint);
  background: transparent; cursor: pointer; flex: none; margin: 1px 0 0; position: relative;
  transition: background 0.15s, border-color 0.15s;
}
.task .check:hover { border-color: var(--accent); }
.task .check:checked { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); }
.task .check:checked::after {
  content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px;
  border: solid #0b1020; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.task .meta { font-size: 0.78rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; align-items: center; }
.task .meta .cat { display: inline-flex; align-items: center; gap: 4px; }
.task .carried { color: var(--warning); display: inline-flex; align-items: center; gap: 3px; }
.task .rep { color: var(--accent); display: inline-flex; align-items: center; gap: 3px; }
.task .meta svg, .appt .meta svg { width: 12px; height: 12px; vertical-align: -1px; }

.quick-add {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
}
.quick-add input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); background: transparent; color: var(--text); outline: none;
}
.quick-add input:focus { border-style: solid; border-color: var(--accent); background: var(--bg); }
.quick-add input::placeholder { color: var(--faint); }

/* ── week view ───────────────────────────────────────────────────────────── */

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}
.day-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, background 0.15s;
}
.day-col.today { border-color: var(--accent-strong); }
.day-col.past { opacity: 0.85; }
.day-col.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.day-col-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.day-col-head .dow { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.day-col-head .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; font-weight: 600;
}
.day-col.today .num { background: var(--accent); color: #0b1020; }
.day-col-head .grow { flex: 1; }
.day-col-head .btn-icon { width: 28px; height: 28px; opacity: 0; transition: opacity 0.15s; }
.day-col:hover .day-col-head .btn-icon, .day-col-head .btn-icon:focus { opacity: 1; }
.day-col .appts { margin-bottom: 8px; }
.day-col .appt { padding: 5px 8px; margin-bottom: 4px; flex-direction: column; gap: 1px; }
.day-col .appt .title { font-size: 0.85rem; white-space: normal; }
.day-col .appt .time { min-width: 0; font-size: 0.75rem; }
.day-col .tasks { flex: 1; }
.progress {
  height: 3px; border-radius: 2px; background: var(--surface-3); overflow: hidden; margin-bottom: 8px;
}
.progress > span { display: block; height: 100%; background: var(--success); transition: width 0.3s; }

/* ── agenda / upcoming ───────────────────────────────────────────────────── */

.agenda-day { margin-bottom: 18px; }
.agenda-day h3 {
  font-size: 0.95rem; display: flex; align-items: center; gap: 10px; margin-bottom: 8px; color: var(--text);
}
.agenda-day h3 .rel { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.agenda-day.today h3 .d { color: var(--accent); }
.agenda-items { display: grid; gap: 4px; }
@media (min-width: 900px) {
  .agenda-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
}

/* ── settings lists ──────────────────────────────────────────────────────── */

.list { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 0.8rem; color: var(--muted); }
.row .actions { display: flex; gap: 4px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.pill {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.pill.accent { color: var(--accent); border-color: rgba(122, 162, 247, 0.4); }
.pill.warn { color: var(--warning); border-color: rgba(224, 175, 104, 0.4); }
.pill.danger { color: var(--danger); border-color: rgba(247, 118, 142, 0.4); }
.pill.ok { color: var(--success); border-color: rgba(158, 206, 106, 0.4); }

.color-options { display: flex; flex-wrap: wrap; gap: 8px; }
.color-options button {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.color-options button.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--bg); }

/* ── modal ───────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 7, 10, 0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade 0.15s ease-out;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
  animation: rise 0.18s ease-out;
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.modal-head h2 { font-size: 1.15rem; flex: 1; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 100; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 999px; padding: 10px 18px;
  box-shadow: var(--shadow); font-size: 0.92rem; max-width: calc(100vw - 32px);
}
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ── segmented control ───────────────────────────────────────────────────── */

.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.segmented button {
  border: 0; background: none; color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 0.85rem;
}
.segmented button.active { background: var(--surface-3); color: var(--text); }

/* ── bottom navigation (mobile) ──────────────────────────────────────────── */

.bottom-nav { display: none; }

/* ── search results ──────────────────────────────────────────────────────── */

.results { display: grid; gap: 6px; }

/* ── responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .week-grid { grid-template-columns: 1fr; }
  .day-col { min-height: 0; }
  .day-col.past.empty-day { display: none; }
  .day-col-head .btn-icon { opacity: 1; }
  .day-cell { min-height: 72px; padding: 4px; }
  .chip { font-size: 0.68rem; padding: 1px 4px; }
  .chip .t { display: none; }
  .view-head h2 { font-size: 1.15rem; min-width: 0; }
}

@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .tabs { display: none; }
  .search { width: auto; flex: 1; }
  .topbar .btn-icon { flex: none; }
  .main { padding: 12px; padding-bottom: calc(80px + var(--safe-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: rgba(14, 17, 22, 0.92); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); padding: 6px 8px calc(6px + var(--safe-bottom));
  }
  .bottom-nav button {
    flex: 1; border: 0; background: none; color: var(--muted); padding: 6px 4px;
    display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.72rem; cursor: pointer;
    border-radius: 10px;
  }
  .bottom-nav button.active { color: var(--accent); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .day-cell { min-height: 60px; }
  .day-cell .chip .title { display: none; }
  .day-cell .chip { width: 8px; height: 8px; border-radius: 50%; padding: 0; border: 0; background: var(--c, var(--accent)); display: inline-block; }
  .day-cell .chips { display: flex; flex-wrap: wrap; gap: 3px; }
  .day-cell .chip.more { width: auto; height: auto; background: none; font-size: 0.65rem; }
  .task-count { font-size: 0.65rem; padding: 0 5px; }
  .modal { padding: 18px; max-height: calc(100vh - 24px); }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .form-actions .btn { flex: 1; }
  .day-panel { position: static; }
}

@media (min-width: 721px) {
  .day-cell .chips { display: flex; flex-direction: column; gap: 2px; }
}

@media (max-width: 460px) {
  .brand > span:last-child { display: none; }
}
