/* ==========================================================================
   Perfice Todo stylesheet
   Colours follow the QES-IT house style: blue #1e7cab, olive #aba713, Lato.
   Light and dark themes are driven by CSS custom properties; the theme follows
   the operating system unless the user picks one (data-theme on <html>).
   ========================================================================== */

@font-face { font-family: "Lato"; src: url("../fonts/Lato-Light.ttf") format("truetype"); font-weight: 300; font-display: swap; }
@font-face { font-family: "Lato"; src: url("../fonts/Lato-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Lato"; src: url("../fonts/Lato-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Lato"; src: url("../fonts/Lato-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --brand: #1e7cab;
  --brand-strong: #17648a;
  --brand-soft: rgba(30, 124, 171, 0.12);
  --accent: #aba713;
  --accent-soft: rgba(171, 167, 19, 0.16);

  --p1: #d1453b;
  --p2: #e8890c;
  --p3: #1e7cab;
  --p4: #9aa0a6;

  --due-overdue: #d1453b;
  --due-today: #2e8b3d;
  --due-tomorrow: #b06a00;
  --due-week: #7a4fc4;

  --radius: 10px;
  --radius-small: 6px;
  --sidebar-width: 280px;
  --detail-width: 440px;
  --shadow: 0 10px 30px rgba(15, 30, 45, 0.18);
  --transition: 160ms cubic-bezier(.2, .8, .2, 1);

  /* Light theme (default). */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --sidebar: #eef2f5;
  --text: #1d2329;
  --text-muted: #67717c;
  --border: #e1e5ea;
  --hover: rgba(30, 124, 171, 0.07);
  --input: #ffffff;
  color-scheme: light;
}

/* Dark theme: explicit choice or system preference. */
:root[data-theme="dark"] {
  --bg: #15181c;
  --surface: #1d2126;
  --surface-2: #252a30;
  --sidebar: #1a1e23;
  --text: #e8eaed;
  --text-muted: #9aa3ad;
  --border: #2e343b;
  --hover: rgba(120, 180, 220, 0.08);
  --input: #22272d;
  --brand-soft: rgba(62, 160, 210, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --surface: #1d2126;
    --surface-2: #252a30;
    --sidebar: #1a1e23;
    --text: #e8eaed;
    --text-muted: #9aa3ad;
    --border: #2e343b;
    --hover: rgba(120, 180, 220, 0.08);
    --input: #22272d;
    --brand-soft: rgba(62, 160, 210, 0.16);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  font-family: "Lato", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Buttons and inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-small);
  padding: 7px 14px; cursor: pointer; font-weight: 700; font-size: 14px;
  background: var(--surface-2); color: var(--text);
  transition: background var(--transition), transform var(--transition);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.accent { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--p1); border-color: var(--p1); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: none; border-radius: var(--radius-small); background: transparent; cursor: pointer; color: var(--text-muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; }

.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-small);
  background: var(--input); outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
.checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.error-text { color: var(--p1); font-size: 14px; min-height: 1.2em; }

/* ---------- Login ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, rgba(171, 167, 19, 0.9), rgba(30, 124, 171, 0.95));
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; margin-bottom: 24px; font-size: 26px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100%; }
.sidebar {
  width: var(--sidebar-width); flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 14px 10px;
  transition: transform var(--transition);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 300; font-size: 21px; letter-spacing: 0.3px; padding: 4px 8px 14px; }
.brand img { width: 30px; height: 30px; }
.brand b { font-weight: 700; color: var(--brand); }
.search { margin: 0 4px 10px; }
.search .input { padding: 7px 10px; font-size: 14px; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-small);
  cursor: pointer; color: var(--text); user-select: none;
}
.nav-item:hover { background: var(--hover); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.nav-item .dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 5px; flex-shrink: 0; }
.nav-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-heading {
  display: flex; align-items: center; justify-content: space-between; margin: 18px 10px 4px;
  font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px;
}
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.quick-add-btn { margin: 0 4px 12px; justify-content: flex-start; }

.main { flex: 1; overflow-y: auto; min-width: 0; }
.main-inner { max-width: 820px; margin: 0 auto; padding: 28px 32px 120px; }
.view-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.view-header h1 { margin: 0; font-size: 24px; font-weight: 700; }
.view-header .sub { color: var(--text-muted); font-size: 13px; margin-left: 4px; }
.view-header .actions { margin-left: auto; display: flex; gap: 4px; }
.menu-toggle { display: none; }

/* ---------- Task list ---------- */
.group { margin-bottom: 22px; }
.group-title {
  display: flex; align-items: baseline; gap: 8px; font-size: 14px; font-weight: 700;
  padding: 6px 0; border-bottom: 1px solid var(--border); margin-bottom: 2px;
}
.group-title.overdue { color: var(--due-overdue); }
.group-title .meta { font-weight: 400; color: var(--text-muted); font-size: 13px; }
.group-title .actions { margin-left: auto; }

.task {
  display: flex; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--border);
  cursor: pointer; position: relative; animation: fade-in 180ms ease-out;
  transition: background var(--transition), opacity 250ms, transform 250ms;
}
.task:hover { background: var(--hover); }
.task.selected { background: var(--brand-soft); }
.task.completing { opacity: 0; transform: translateX(16px); }
.task.sub { padding-left: calc(6px + var(--depth, 0) * 28px); }
.task-body { flex: 1; min-width: 0; }
.task-content { word-wrap: break-word; }
.task.done .task-content { text-decoration: line-through; color: var(--text-muted); }
.task-desc { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 3px; font-size: 12.5px; color: var(--text-muted); }
.task-meta span { display: inline-flex; align-items: center; gap: 3px; }
.task-meta svg { width: 14px; height: 14px; }
.task-meta .project { margin-left: auto; }
.task-meta .project .dot { width: 8px; height: 8px; border-radius: 50%; }
.due.overdue { color: var(--due-overdue); }
.due.today { color: var(--due-today); }
.due.tomorrow { color: var(--due-tomorrow); }
.due.week { color: var(--due-week); }

/* Round checkbox coloured by priority, like the Todoist widget. */
.check {
  flex-shrink: 0; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--p4); background: transparent; cursor: pointer; padding: 0;
  display: grid; place-items: center; transition: background var(--transition), transform var(--transition);
}
.check svg { width: 12px; height: 12px; opacity: 0; color: #fff; transition: opacity var(--transition); }
.check:hover svg { opacity: 0.6; color: var(--check-color, var(--p4)); }
.check.p1 { --check-color: var(--p1); border-color: var(--p1); background: rgba(209, 69, 59, 0.1); }
.check.p2 { --check-color: var(--p2); border-color: var(--p2); background: rgba(232, 137, 12, 0.1); }
.check.p3 { --check-color: var(--p3); border-color: var(--p3); background: rgba(30, 124, 171, 0.1); }
.check.checked { background: var(--check-color, var(--p4)); transform: scale(1.1); }
.check.checked svg { opacity: 1; color: #fff; }

.add-task {
  display: flex; align-items: center; gap: 10px; padding: 10px 6px; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-small);
}
.add-task:hover { color: var(--brand); }
.add-task svg { width: 20px; height: 20px; }
.add-form { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--surface); margin: 8px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.add-form .input { border: none; box-shadow: none; padding: 6px 4px; }
.add-form .hint { font-size: 12px; color: var(--text-muted); padding: 0 4px 8px; }
.add-form .row { display: flex; gap: 8px; justify-content: flex-end; align-items: center; border-top: 1px solid var(--border); padding-top: 8px; }
.add-form .row select { width: auto; margin-right: auto; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty img { width: 64px; opacity: 0.8; margin-bottom: 12px; }

/* ---------- Detail drawer ---------- */
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--detail-width); max-width: 100%;
  background: var(--surface); box-shadow: var(--shadow); z-index: 30; display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
}
.detail.open { transform: none; }
.detail-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.detail-head .crumb { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.detail-head .crumb .dot { width: 8px; height: 8px; border-radius: 50%; }
.detail-head .spacer { flex: 1; }
.detail-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }
.detail-title { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.detail-title textarea { font-size: 18px; font-weight: 700; border: 1px solid transparent; resize: none; padding: 2px 6px; min-height: 0; overflow: hidden; }
.detail-title textarea:hover { border-color: var(--border); }
.detail-desc textarea { border-color: transparent; min-height: 60px; }
.detail-desc textarea:hover { border-color: var(--border); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 18px; }
.detail-grid .full { grid-column: 1 / -1; }
.detail-section { margin-top: 22px; }
.detail-section h3 { font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.recurring-note { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.recurring-note svg { width: 14px; height: 14px; }
.detail-section h3 svg { width: 16px; height: 16px; color: var(--text-muted); }

.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.comment .body { flex: 1; min-width: 0; white-space: pre-wrap; word-wrap: break-word; }
.comment .when { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }
.comment-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.comment-form .btn { align-self: flex-end; }

/* ---------- Modal ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 20, 30, 0.45); z-index: 40; display: grid; place-items: start center; padding: 12vh 16px 16px; animation: fade-in 120ms; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 18px; animation: pop-in 160ms cubic-bezier(.2, .8, .2, 1); }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* ---------- Settings ---------- */
.settings section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.settings h2 { font-size: 17px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.settings h2 svg { width: 20px; height: 20px; color: var(--brand); }
.settings p.lead { margin: 0 0 14px; color: var(--text-muted); font-size: 14px; }
.settings .inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.settings .inline > * { flex: 1; min-width: 160px; }
.settings .inline > .btn { flex: 0 0 auto; height: 40px; }
.settings .inline .field { margin-bottom: 0; }
.settings .inline { margin-bottom: 12px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-muted); }
.badge.on { background: rgba(46, 139, 61, 0.15); color: var(--due-today); }
.badge.warn { background: rgba(209, 69, 59, 0.12); color: var(--p1); }
table.keys { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
table.keys th { text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 700; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.keys td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.secret-box { display: flex; gap: 8px; align-items: center; background: var(--accent-soft); border-radius: var(--radius-small); padding: 10px 12px; margin-top: 10px; word-break: break-all; }
.secret-box code { background: transparent; flex: 1; }
.qr { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.qr img { width: 180px; height: 180px; background: #fff; padding: 8px; border-radius: 8px; }
pre.example { background: var(--surface-2); border-radius: var(--radius-small); padding: 12px; overflow-x: auto; font-size: 13px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1d2329; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; animation: pop-in 160ms; font-size: 14px; }
.toast button { background: none; border: none; color: #7cc7ee; font-weight: 700; cursor: pointer; }
.toast.error { background: var(--p1); }

/* ---------- Animations ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 35; top: 0; bottom: 0; left: 0; transform: translateX(-105%); box-shadow: var(--shadow); }
  .app.menu-open .sidebar { transform: none; }
  .menu-toggle { display: inline-grid; }
  .main-inner { padding: 16px 14px 120px; }
  .detail { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .backdrop { padding-top: 8vh; }
}
