/* DiTa brand palette */
:root {
  --navy: #1974D2;
  --dark: #19213D;
  --red: #ED2939;
  --red-bright: #FF2D46;
  --mango: #FFC229;
  --green: #05994A;

  --bg: #0f1428;
  --bg-elev: #19213D;
  --bg-elev-2: #222b4d;
  --border: #2a365f;
  --text: #e7ebf5;
  --muted: #8893b5;
  --primary: var(--navy);
  --danger: var(--red);
  --warning: var(--mango);
  --success: var(--green);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: 'Inter', 'Google Sans', 'Lato', -apple-system, system-ui, sans-serif;

  --topbar-h: 54px;
  --toolbar-h: 56px;
}

html[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f3fa;
  --border: #e3e7f2;
  --text: #19213D;
  --muted: #6a7490;
  --shadow: 0 6px 20px rgba(25, 33, 61, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { touch-action: manipulation; }

kbd {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--muted);
}

#app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ===== Mobile top bar — hidden on desktop ===== */
.mobile-topbar {
  display: none;
  position: sticky; top: 0; left: 0; right: 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  z-index: 20;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}
.mob-title { font-weight: 700; font-size: 16px; text-align: center; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-elev-2); }

/* ===== Sidebar ===== */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-backdrop { display: none; }

.brand { padding: 4px 8px 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.brand-mark { font-weight: 800; font-size: 24px; letter-spacing: -0.5px; color: var(--primary); }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: transparent; border: none;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
  text-align: left; font-size: 14px; font-weight: 500;
  min-height: 44px;
}
.nav-item:hover { background: var(--bg-elev-2); }
.nav-item.active { background: var(--primary); color: white; }
.nav-item.active .nav-count { background: rgba(255,255,255,.2); color: white; }
.nav-icon { width: 20px; text-align: center; }
.nav-item span:nth-child(2) { flex: 1; }
.nav-count {
  background: var(--bg-elev-2); color: var(--muted);
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
  min-width: 22px; text-align: center;
}
.nav-count.overdue { background: rgba(237, 41, 57, .18); color: #ff8290; }

.section-label {
  margin: 22px 0 8px; padding: 0 10px;
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
}
.shortcuts { font-size: 11.5px; color: var(--muted); padding: 0 10px; display: flex; flex-direction: column; gap: 6px; }

.sidebar-footer {
  margin-top: auto; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.footer-btn {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12px;
  min-height: 40px;
}
.footer-btn:hover { border-color: var(--primary); }

/* ===== Main ===== */
.main {
  overflow-y: auto;
  padding: 24px 32px;
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
}
.main-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
.main-header h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; }
#search {
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: var(--radius);
  min-width: 240px; color: var(--text);
  font-size: 14px;
}
#search:focus { outline: none; border-color: var(--primary); }

/* ===== OUTLINE ===== */
.outline { max-width: 920px; }
.outline-empty {
  text-align: center; padding: 60px 20px; color: var(--muted);
  background: var(--bg-elev); border: 1px dashed var(--border); border-radius: var(--radius);
}
.outline-empty .icon { font-size: 42px; margin-bottom: 10px; }

.node {
  position: relative;
  padding: 1px 0;
}
.node-children {
  margin-left: 22px;
  border-left: 1px dashed transparent;
  padding-left: 6px;
  transition: border-color 0.15s;
}
.node:hover > .node-children,
.node.has-focus > .node-children {
  border-left-color: var(--border);
}

.node-row {
  display: flex; align-items: flex-start;
  gap: 2px;
  padding: 6px 6px; border-radius: var(--radius-sm);
  min-height: 36px;
}
.node-row:hover { background: var(--bg-elev-2); }
.node-row.focused { background: var(--bg-elev); }

.caret {
  width: 22px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer; flex-shrink: 0;
  background: none; border: none; padding: 0; font-size: 10px;
  opacity: 0.4;
  transition: opacity 0.1s;
}
.node.has-children > .node-row > .caret { opacity: 0.75; }
.node.collapsed > .node-row > .caret { color: var(--mango); opacity: 1; }
.caret:hover { color: var(--primary); opacity: 1; }

.bullet {
  width: 22px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  background: none; border: none; padding: 0;
}
.bullet::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text); opacity: 0.7;
  transition: all 0.15s;
}
.node.has-children > .node-row > .bullet::before {
  background: var(--primary);
  box-shadow: 0 0 0 5px rgba(25, 116, 210, 0.15);
}
.node.collapsed > .node-row > .bullet::before {
  background: var(--mango);
  box-shadow: 0 0 0 5px rgba(255, 194, 41, 0.18);
}
.bullet:hover::before { background: var(--primary); transform: scale(1.3); }

.checkbox {
  width: 22px; height: 22px; margin-top: 4px;
  border: 1.5px solid var(--border); border-radius: 5px;
  background: transparent; cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: transparent; font-size: 13px;
}
.checkbox:hover, .checkbox:active { border-color: var(--primary); }
.node.done > .node-row > .checkbox {
  background: var(--success); border-color: var(--success); color: white;
}

.text-wrap {
  flex: 1; min-width: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding-left: 4px;
}
.text {
  flex: 1 1 180px; min-width: 100px;
  background: transparent; border: none; padding: 4px 4px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  color: var(--text); outline: none;
  font-family: inherit;
  word-break: break-word; white-space: pre-wrap;
  min-height: 26px;
  line-height: 1.4;
}
.text:focus { background: var(--bg); border-radius: 4px; }
.text[contenteditable=true]:empty::before {
  content: attr(data-placeholder);
  color: var(--muted); opacity: 0.5;
}
.node.done > .node-row > .text-wrap > .text { color: var(--muted); text-decoration: line-through; }

.date-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  background: rgba(25, 116, 210, 0.15); color: #74b4f0;
  border: 1px solid transparent;
  flex-shrink: 0;
  min-height: 26px;
}
.date-chip:hover, .date-chip:active { border-color: var(--primary); }
.date-chip.today { background: rgba(5, 153, 74, .16); color: #35d386; }
.date-chip.overdue { background: rgba(237, 41, 57, .18); color: #ff8290; }
.date-chip.past { background: var(--bg-elev-2); color: var(--muted); }

.add-date {
  width: 26px; height: 26px; border-radius: 50%;
  background: transparent; border: 1px dashed var(--border); color: var(--muted);
  cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.4; transition: opacity 0.1s;
  flex-shrink: 0;
}
.node:hover > .node-row > .text-wrap > .add-date,
.node-row.focused > .text-wrap > .add-date { opacity: 0.9; }
.add-date:hover { color: var(--primary); border-color: var(--primary); }

.node-actions {
  display: flex; gap: 2px; align-self: flex-start;
  opacity: 0; transition: opacity 0.1s;
}
.node:hover > .node-row > .node-actions { opacity: 1; }
.act-btn {
  width: 28px; height: 28px;
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; border-radius: 4px;
}
.act-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.act-btn.danger:hover { color: var(--danger); }

/* Add root button */
.add-root {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-size: 14px;
  min-height: 46px;
}
.add-root:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Calendar ===== */
.cal-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.cal-head h2 { margin: 0; font-size: 20px; font-weight: 700; flex: 1; }
.cal-nav { display: flex; gap: 6px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  min-height: 40px; font-size: 13px;
}
.btn-ghost:hover { border-color: var(--primary); }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 10px; border-radius: var(--radius);
}
.cal-dow {
  text-align: center; padding: 6px 0;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted);
}
.cal-day {
  min-height: 86px; background: var(--bg);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 6px 6px; cursor: pointer;
}
.cal-day.other-month { opacity: 0.4; }
.cal-day.today { border-color: var(--primary); }
.cal-day.selected { background: var(--bg-elev-2); border-color: var(--primary); }
.cal-day .d-num { font-weight: 600; font-size: 13px; }
.cal-day.today .d-num { color: var(--primary); }
.cal-day .d-tasks { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.cal-task {
  font-size: 10.5px; background: var(--bg-elev-2); padding: 2px 6px;
  border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-left: 2px solid var(--primary);
}
.cal-task.done { opacity: 0.5; text-decoration: line-through; }
.cal-day .more { font-size: 10px; color: var(--muted); margin-top: 2px; }
.cal-selected {
  margin-top: 16px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.cal-selected h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.cal-item {
  padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm);
  margin-bottom: 6px; cursor: pointer; border-left: 3px solid var(--primary);
  min-height: 44px;
}
.cal-item:hover { background: var(--bg-elev-2); }
.cal-item.done { opacity: 0.55; text-decoration: line-through; }
.cal-item .ctx { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ===== List views ===== */
.day-group { margin-bottom: 20px; }
.day-head {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin: 0 0 10px 2px;
  display: flex; justify-content: space-between;
}
.day-head .d-date { color: var(--primary); }
.list-item {
  padding: 12px 14px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  min-height: 54px;
}
.list-item:hover { border-color: var(--primary); }
.list-item.done { opacity: 0.55; }
.list-item.done .li-text { text-decoration: line-through; color: var(--muted); }
.list-item.overdue { border-left: 3px solid var(--danger); }
.list-item .li-check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
  flex-shrink: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  color: transparent; font-size: 12px;
}
.list-item.done .li-check { background: var(--success); border-color: var(--success); color: white; }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-text { font-size: 14.5px; font-weight: 500; }
.list-item .li-breadcrumb {
  font-size: 11.5px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--text); z-index: 100; font-size: 13px; font-weight: 500;
  max-width: calc(100vw - 40px);
}

/* ===== Date picker popover ===== */
.date-pop {
  position: fixed; z-index: 50;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
  min-width: 260px;
}
.dp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 4px 8px 10px; font-weight: 600;
}
.dp-head button {
  background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 6px 12px;
  border-radius: 4px; font-size: 16px;
}
.dp-head button:hover { background: var(--bg-elev-2); color: var(--text); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-dow { text-align: center; font-size: 10px; color: var(--muted); padding: 4px 0; font-weight: 600; }
.dp-day {
  padding: 10px 0; text-align: center; border-radius: 4px; cursor: pointer;
  font-size: 13px; min-height: 36px;
}
.dp-day:hover, .dp-day:active { background: var(--bg-elev-2); }
.dp-day.other { color: var(--muted); opacity: 0.5; }
.dp-day.today { color: var(--primary); font-weight: 700; }
.dp-day.sel { background: var(--primary); color: white; }
.dp-actions {
  display: flex; gap: 6px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.dp-actions button { flex: 1; padding: 8px 10px; font-size: 13px; min-height: 40px; }

/* ===== Floating action toolbar ===== */
.float-toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  gap: 2px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  z-index: 40;
  max-width: calc(100vw - 20px);
  overflow-x: auto;
}
.ft-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 46px; height: 46px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ft-btn:hover, .ft-btn:active { background: var(--bg-elev-2); }
.ft-btn.danger:hover, .ft-btn.danger:active { background: rgba(237, 41, 57, .18); color: var(--danger); }

/* ===== Mobile search bar ===== */
.mobile-search {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  z-index: 30;
  gap: 10px;
  align-items: center;
}
.mobile-search input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 14px; border-radius: var(--radius);
  color: var(--text); font-size: 15px;
}
.mobile-search input:focus { outline: none; border-color: var(--primary); }

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* =========================================================
   MOBILE
   ========================================================= */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .mobile-topbar { display: grid; }
  .main-header .header-actions { display: none; }
  .main-header h1 { font-size: 20px; }
  .main-header { margin-bottom: 14px; }
  .main { padding: 14px; padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 85%; max-width: 320px; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  /* Larger tap targets everywhere */
  .checkbox { width: 24px; height: 24px; }
  .bullet { width: 26px; height: 32px; }
  .caret { width: 26px; height: 32px; }
  .text { font-size: 16px; padding: 6px 4px; min-height: 30px; }
  .add-date { opacity: 0.9; } /* always visible on mobile */
  .node-actions { display: none; } /* use floating toolbar instead */
  .node-row { padding: 8px 6px; min-height: 46px; }

  .mobile-search { display: flex; }
  .mobile-search[hidden] { display: none; }

  .cal-day { min-height: 56px; padding: 4px 4px; }
  .cal-task { font-size: 9.5px; padding: 1px 4px; }
  .cal-grid { padding: 6px; }

  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

  .float-toolbar {
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    justify-content: space-between;
  }
  .ft-btn { width: 42px; height: 44px; font-size: 17px; }
}

@media (max-width: 400px) {
  .brand-mark { font-size: 20px; }
  .main-header h1 { font-size: 18px; }
  .cal-dow { font-size: 10px; }
  .ft-btn { width: 38px; height: 42px; font-size: 16px; }
}
