/* ==========================================================================
   Mindlist — Base Styles
   HMS Foundation · styles.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Theme Tokens)
   All views MUST consume these variables; never hardcode colour values.
   -------------------------------------------------------------------------- */
:root {
  /* Backgrounds */
  --bg:       #fafafa;
  --surface:  #ffffff;
  --hover:    #f0f0f0;

  /* Text */
  --text:     #202020;
  --subtext:  #808080;
  --muted:    #a8a8a8;

  /* Borders & chrome */
  --border:   #e5e5e5;

  /* Brand accent — Todoist red */
  --accent:   #db4c3f;

  /* Priority colours */
  --p1: #d1453b;   /* P1 — Urgent  */
  --p2: #eb8909;   /* P2 — High    */
  --p3: #246fe0;   /* P3 — Medium  */
  --p4: #808080;   /* P4 — Normal  */

  /* Radii */
  --radius:    6px;
  --radius-lg: 10px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.14);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

ul,
ol {
  list-style: none;
}

/* --------------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}

.subtext {
  color: var(--subtext);
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   Layout — Sidebar + Main grid
   -------------------------------------------------------------------------- */
.sidebar {
  width: 260px;
  min-width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #f5f3f0;
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow-y: auto;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  user-select: none;
}

/* Brand logo — small red square */
.brand-logo {
  display: inline-block;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 4px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Project list */
#project-list {
  flex: 1;
  padding: 4px 8px;
}

/* Individual project rows (rendered by Lighthouse) */
#project-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  transition: background 100ms;
}

#project-list li:hover {
  background: var(--hover);
}

#project-list li.active {
  background: rgba(219, 76, 63, 0.1);
  color: var(--accent);
  font-weight: 600;
}

/* Add-project button */
.btn-add-project {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 16px);
  margin: 6px 8px 14px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--subtext);
  font-size: 14px;
  text-align: left;
  transition: background 100ms, color 100ms;
}

.btn-add-project:hover {
  background: var(--hover);
  color: var(--text);
}

.add-project-icon {
  font-size: 18px;
  line-height: 1;
  font-weight: 400;
  color: inherit;
}

/* --------------------------------------------------------------------------
   Topbar
   -------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#project-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

#task-count {
  font-size: 13px;
  color: var(--subtext);
}

.topbar-right {
  flex-shrink: 0;
  margin-left: 16px;
}

/* View toggle pill */
.view-toggle {
  display: inline-flex;
  background: var(--hover);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--subtext);
  transition: background 120ms, color 120ms;
}

.view-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
}

.view-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Views
   -------------------------------------------------------------------------- */
.view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* .hidden is already declared above — views get it too */

/* --------------------------------------------------------------------------
   Mind-map toolbar
   -------------------------------------------------------------------------- */
#mindmap-view {
  display: flex;
  flex-direction: column;
  padding: 0;
  position: relative;
}

.mm-toolbar {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  box-shadow: var(--shadow-sm);
}

.mm-btn {
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 100ms;
}

.mm-btn:hover {
  background: var(--hover);
}

.mm-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mm-toolbar-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}

.mm-zoom-readout {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--subtext);
  min-width: 38px;
  text-align: center;
}

.mm-hint {
  font-size: 12px;
  color: var(--muted);
  margin-left: 8px;
  user-select: none;
}

/* Mind-map canvas */
.mm-canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#mm-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: filter 120ms;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  background: var(--hover);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: background 100ms;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-danger {
  background: transparent;
  color: var(--p1);
}

.btn-danger:hover {
  background: rgba(209, 69, 59, 0.08);
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  z-index: 100;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal.hidden {
  display: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--subtext);
  transition: background 100ms, color 100ms;
}

.modal-close-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.modal-close-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

.modal-footer-actions {
  display: flex;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   Form fields (modal)
   -------------------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field-row {
  display: flex;
  gap: 16px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--subtext);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(219, 76, 63, 0.15);
}

.field-input::placeholder {
  color: var(--muted);
}

.field-textarea {
  resize: vertical;
  min-height: 72px;
}

.field-select {
  appearance: auto;
}

/* --------------------------------------------------------------------------
   Priority dots (shared across list and mind-map views)
   -------------------------------------------------------------------------- */
.priority-1::before,
.priority-2::before,
.priority-3::before,
.priority-4::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.priority-1::before { background: var(--p1); }
.priority-2::before { background: var(--p2); }
.priority-3::before { background: var(--p3); }
.priority-4::before { background: var(--p4); }

/* --------------------------------------------------------------------------
   Hamburger toggle — hidden on desktop, shown only at ≤640px
   -------------------------------------------------------------------------- */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  color: var(--text);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Sidebar backdrop — hidden by default; shown on mobile when drawer open
   -------------------------------------------------------------------------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Mobile — ≤640px
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Hamburger: show as icon button with adequate tap target */
  .sidebar-toggle {
    display: inline-flex;
    min-width: 40px;
    min-height: 40px;
  }

  .sidebar-toggle:hover {
    background: var(--hover);
  }

  /* Sidebar becomes a fixed left drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 80vw);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    z-index: 50;
  }

  /* Slide in when drawer is open */
  body.drawer-open .sidebar {
    transform: translateX(0);
  }

  /* Show backdrop when drawer is open (override .hidden utility) */
  body.drawer-open .sidebar-backdrop {
    display: block !important;
    pointer-events: auto;
  }

  /* Main fills the full viewport — sidebar is out of flow when fixed */
  .main {
    width: 100%;
    flex: 1;
  }

  /* Topbar: tighter padding so hamburger + title + view-toggle all fit */
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .topbar-left {
    flex: 1;
    min-width: 0;
  }

  /* Allow topbar-right to shrink so view-toggle pill fits within 390px */
  .topbar-right {
    flex-shrink: 1;
    min-width: 0;
  }

  /* Hide SVG icons inside view buttons — saves ~24px per button on mobile */
  .view-btn svg {
    display: none;
  }

  /* Slightly compact view buttons */
  .view-btn {
    padding: 5px 8px;
    font-size: 12px;
  }

  /* Hard cap — prevent any element from forcing the page wider than the viewport */
  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Modal: near-full-width, anchored near top */
  .modal {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    max-height: calc(100% - 48px);
    overflow: auto;
  }

  /* Reduced modal inner padding */
  .modal-header {
    padding: 14px 16px 12px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px 14px;
  }
}
