/* ===== Tokens ===== */
:root {
  --bg: #FBF6EE;
  --surface: #FFFEFB;
  --surface-raised: #F4EBDC;
  --border: #E9DCC5;
  --text: #2C2116;
  --text-muted: #8A7A64;
  --accent: #B1592A;
  --accent-contrast: #FFFEFB;
  --danger: #A63D2E;
  --high: #A63D2E;
  --normal: #A87A24;
  --low: #8A7A64;
  --radius: 14px;
  --shadow: 0 10px 28px rgba(60, 40, 20, 0.10);
  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

[data-theme="dark"] {
  --bg: #221A12;
  --surface: #2B2116;
  --surface-raised: #382C1C;
  --border: #4A3B26;
  --text: #F5EBDC;
  --text-muted: #BBA989;
  --accent: #E08A4E;
  --accent-contrast: #241505;
  --danger: #E27C64;
  --high: #E27C64;
  --normal: #E0B45C;
  --low: #BBA989;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.brand, .login-title { font-family: var(--font-display); }
button { font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-small { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-raised); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid var(--border); margin-top: 8px; }
.btn-danger-ghost:hover { background: var(--surface-raised); }
.icon-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-raised); color: var(--text); }

/* ===== Login ===== */
.screen-login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-title { font-size: 26px; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); margin: 0 0 20px; font-size: 13.5px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.form-error { color: var(--danger); font-size: 13px; margin: -6px 0 14px; }
.form-info { color: var(--text-muted); font-size: 13px; margin: -6px 0 14px; }

/* ===== App layout ===== */
.screen-app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 14px; }
.brand { font-weight: 650; font-size: 16px; }
.nav-group { margin-top: 20px; }
.nav-group-grow { flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: none; color: var(--text-muted); margin: 0; }
.nav-label-row { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px 6px; }
.nav-label-row .icon-btn { font-size: 15px; padding: 2px 8px; }
.quick-list-form { padding: 0 6px 8px; }
.quick-list-form input { padding: 7px 9px; font-size: 13px; }
.nav-item-muted { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-raised); }
.nav-item.active { background: var(--surface-raised); font-weight: 600; }
.count { color: var(--text-muted); font-size: 12px; }
.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.sidebar-toggle { display: none; position: fixed; top: 10px; left: 10px; z-index: 20; background: var(--surface); border: 1px solid var(--border); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.main-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 28px 4px; gap: 16px; }
.main-header h1 { font-size: 22px; }
.search-box input { width: 220px; }
.quick-add-bar { padding: 14px 28px; }
.quick-add-row { display: flex; gap: 8px; align-items: center; }
.quick-add-row input { padding: 12px 14px; font-size: 14.5px; }
.quick-add-details {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin-top: 10px; padding: 12px; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.qd-field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.qd-field span { font-size: 12px; color: var(--text-muted); }
.qd-field input, .qd-field select { padding: 7px 9px; font-size: 13px; }

.task-list { list-style: none; margin: 0; padding: 0 28px 40px; overflow-y: auto; flex: 1; }
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.task-row:hover { background: var(--surface-raised); border-radius: 8px; }
.checkbox {
  margin-top: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.checkbox.checked { background: var(--accent); border-color: var(--accent); }
.checkbox.checked::after { content: '✓'; color: var(--accent-contrast); font-size: 12px; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 14.5px; }
.task-row.completed .task-title { color: var(--text-muted); text-decoration: line-through; }
.task-meta { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 100px; background: var(--surface-raised); color: var(--text-muted); border: 1px solid var(--border); }
.pill-overdue { color: var(--high); border-color: var(--high); }
.priority-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.empty-state { text-align: center; color: var(--text-muted); margin-top: 60px; }

/* ===== Task detail panel ===== */
.task-panel {
  width: 380px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.task-panel-header { display: flex; justify-content: flex-end; padding: 10px; }
.task-panel-body { padding: 4px 24px 30px; display: flex; flex-direction: column; gap: 16px; }
.tp-title { font-size: 18px; font-weight: 600; border: none; padding: 4px 0; resize: none; background: transparent; }
.tp-row { display: flex; gap: 12px; }
.tp-field { display: block; }
.tp-field span { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag-chip { font-size: 12px; padding: 3px 9px; border-radius: 100px; background: var(--surface-raised); border: 1px solid var(--border); display: flex; align-items: center; gap: 6px; }
.tag-chip button { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 12px; padding: 0; }
.tag-add-row { display: flex; gap: 8px; margin-top: 4px; }
.subtask-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.subtask-row { display: flex; align-items: center; gap: 8px; }
.subtask-row input[type="text"] { border: none; background: transparent; padding: 4px 0; }
.subtask-row.completed input[type="text"] { color: var(--text-muted); text-decoration: line-through; }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  width: 100%; max-width: 460px; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.lists-manage { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.list-manage-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.list-manage-head { display: flex; align-items: center; justify-content: space-between; }
.share-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-size: 13px; }

/* ===== Calendar ===== */
.calendar-pane { padding: 0 28px 40px; overflow-y: auto; flex: 1; }
.calendar-toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 4px 0 14px; }
.calendar-modes { display: flex; gap: 4px; background: var(--surface-raised); border-radius: 8px; padding: 3px; }
.cal-mode-btn { background: transparent; border: none; padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text-muted); }
.cal-mode-btn.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.calendar-nav { display: flex; align-items: center; gap: 6px; }
.calendar-toolbar h2 { font-size: 16px; margin-left: auto; text-transform: capitalize; }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.calendar-grid.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-weekday { background: var(--surface-raised); padding: 8px; font-size: 12px; text-align: center; color: var(--text-muted); }
.cal-day-cell { background: var(--surface); min-height: 108px; padding: 6px; display: flex; flex-direction: column; gap: 3px; }
.cal-day-cell.outside { background: var(--bg); }
.cal-day-cell.today .cal-day-num { background: var(--accent); color: var(--accent-contrast); border-radius: 50%; }
.cal-day-num { font-size: 12.5px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cal-task-chip { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--surface-raised); border-left: 3px solid var(--accent); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-task-chip.completed { opacity: 0.5; text-decoration: line-through; }
.cal-more { font-size: 11px; color: var(--text-muted); cursor: pointer; padding: 0 4px; }

.calendar-grid.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.cal-week-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 220px; }
.cal-week-col-head { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; text-align: center; }
.cal-week-col.today .cal-week-col-head { color: var(--accent); font-weight: 700; }
.cal-task-line { font-size: 12.5px; padding: 5px 7px; border-radius: 7px; background: var(--surface-raised); border-left: 3px solid var(--accent); margin-bottom: 5px; cursor: pointer; }
.cal-task-line .cal-time { color: var(--text-muted); font-size: 11px; display: block; }

.calendar-grid.day { display: flex; flex-direction: column; gap: 8px; max-width: 480px; }

@media (max-width: 860px) {
  .calendar-grid.month { grid-template-columns: repeat(7, minmax(38px, 1fr)); }
  .cal-day-cell { min-height: 70px; padding: 3px; }
  .calendar-grid.week { grid-template-columns: 1fr; }
}
.admin-toolbar { padding: 0 28px; }
.admin-table { padding: 16px 28px 40px; overflow-y: auto; }
.admin-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 10px; border-bottom: 1px solid var(--border);
}
.admin-row .name { font-weight: 600; }
.admin-row .email { color: var(--text-muted); font-size: 13px; }
.admin-row .role-badge { font-size: 11.5px; padding: 2px 8px; border-radius: 100px; background: var(--surface-raised); border: 1px solid var(--border); }
.admin-actions { margin-left: auto; display: flex; gap: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 13.5px;
  z-index: 100; box-shadow: var(--shadow);
}

/* ===== Responsive ===== */
.mobile-only { display: none; }
@media (max-width: 860px) {
  .task-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; width: min(380px, 92vw); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 25; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .search-box { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
