/* ==========================================================================
   nickdrake.ai · Native Apple Dark Mode Personal Second Brain
   Calibrated iOS 18 / macOS Proportions · Zero Horizontal Overflow
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg: #171717;
  --bg-deep: #121212;
  --surface: #202020;
  --surface-subtle: #282828;
  --surface-hover: #303030;
  --text: #f5f5f5;
  --text-sec: #9e9e9e;
  --text-ter: #6e6e6e;
  --border: rgba(255, 255, 255, 0.09);
  --accent: #57b4a2;
  --accent-soft: rgba(87, 180, 162, 0.16);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.15);
  --blue: #0a84ff;
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.15);
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.78);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.38;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

/* Full-Screen App Shell */
.app-shell {
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  margin: 0 auto;
}

/* Top Bar */
.topbar {
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: rgba(20, 20, 20, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.15;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

/* Workspace Body */
.workspace-body {
  flex: 1;
  width: 100%;
  max-width: 100vw;
  display: flex;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* Mac / Computer Sidebar */
.mac-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #141414;
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.app-shell[data-device="iphone"] .mac-sidebar {
  display: none;
}

@media (max-width: 760px) {
  .mac-sidebar {
    display: none;
  }
}

.sidebar-group-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-ter);
  padding: 4px 10px 6px;
}

.side-nav-btn {
  border: 0;
  background: transparent;
  color: var(--text-sec);
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  text-align: left;
}

.side-nav-btn:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.side-nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.side-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sec);
  background: var(--surface-subtle);
  padding: 1px 7px;
  border-radius: 999px;
}

.side-nav-btn.active .side-count {
  background: var(--accent);
  color: #121212;
}

/* Main Stage */
.main-stage {
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 14px 86px;
}

.app-shell[data-device="mac"] .main-stage {
  padding: 20px 28px 40px;
}

.view-section {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* Search Strip */
.search-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 100%;
}

.apple-search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
}

.apple-search-input::placeholder,
.apple-input::placeholder {
  color: var(--text-ter);
}

.apple-search-input:focus,
.apple-input:focus {
  border-color: var(--accent);
}

.btn-ask {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 0 13px;
  border-radius: 10px;
  cursor: pointer;
}

.ask-drawer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Section Hero */
.section-hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 2px;
}

.page-h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.15;
}

.page-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-sec);
}

/* Critical CSS Grid Fix: minmax(0, 1fr) prevents nowrap children from expanding width! */
.two-col-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 100%;
}

.app-shell[data-device="mac"] .two-col-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.ios-group-block {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.ios-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-sec);
  margin: 8px 4px 6px;
}

/* Filter Bar & Chips */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.chip-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  max-width: 100%;
}

.chip-scroll::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sec);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--text);
  color: #121212;
  border-color: var(--text);
}

.apple-input {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  background: #141414;
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
}

.btn-primary-pill {
  border: 0;
  background: var(--accent);
  color: #121212;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-task {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

/* ==========================================================================
   Apple Human Interface Guidelines — Grouped Lists, Checkboxes, Swipe & Context Menu
   ========================================================================== */

.ios-grouped-list {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.ios-swipe-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.ios-swipe-wrap:last-child {
  border-bottom: none;
}

.ios-swipe-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.ios-swipe-bg.swiping-right {
  background: #30d158;
  justify-content: flex-start;
  opacity: 1;
}

.ios-swipe-bg.swiping-left {
  background: #ff453a;
  justify-content: flex-end;
  opacity: 1;
}

.ios-row {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.12s ease;
}

.ios-row:hover {
  background: #262626;
}

.ios-row:active {
  background: #2e2e2e;
}

.ios-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #282828;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.ios-avatar svg {
  width: 15px;
  height: 15px;
  stroke: var(--text-sec);
}

.ios-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.75px solid #6e6e6e;
  background: transparent;
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  font-size: 11px;
  font-weight: 800;
  transition: all 0.15s ease;
}

.ios-check:hover {
  border-color: var(--accent);
}

.ios-check.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #121212;
}

.ios-row-main {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.ios-row-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
  line-height: 1.28;
}

.ios-row.completed .ios-row-title {
  color: var(--text-ter);
  text-decoration: line-through;
}

.ios-row-sub {
  font-size: 12px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.24;
}

.ios-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 4px;
}

.ios-count-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-sec);
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 7px;
  border-radius: 999px;
}

.ios-chevron {
  color: #6e6e6e;
  font-size: 16px;
  line-height: 1;
  font-weight: 400;
}

/* iOS Bottom Tab Bar (Monochrome SF-Symbol SVGs) */
.ios-tabbar {
  flex-shrink: 0;
  width: 100%;
  max-width: 100vw;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: rgba(20, 20, 20, 0.92);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-top: 1px solid var(--border);
  padding: 6px 4px max(10px, env(safe-area-inset-bottom));
  z-index: 25;
}

.app-shell[data-device="mac"] .ios-tabbar {
  display: none;
}

@media (min-width: 761px) {
  .ios-tabbar {
    display: none;
  }
}

.ios-tab {
  border: 0;
  background: transparent;
  color: var(--text-sec);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 2px 10px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.12s ease;
}

.ios-tab.active {
  color: var(--accent);
}

.ios-tab-svg {
  width: 20px;
  height: 20px;
  display: block;
}

.ios-tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Slide-Over Detail Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 8, 0.68);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.app-shell[data-device="mac"] .sheet-backdrop {
  align-items: center;
}

.sheet-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 540px;
  max-height: 86dvh;
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-shell[data-device="mac"] .sheet-panel {
  border-radius: 16px;
  max-width: 640px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sheet-kicker {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent);
  text-transform: uppercase;
}

.sheet-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.btn-close-sheet {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 600;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}

.sheet-body {
  padding: 14px 16px 26px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-block {
  background: #161616;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  color: #eaeaea;
  line-height: 1.42;
}

.detail-block strong {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-sec);
  margin-bottom: 4px;
}

/* iOS Press-and-Hold Blurred Context Menu */
.ios-context-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ios-context-menu {
  width: 100%;
  max-width: 270px;
  background: rgba(36, 36, 36, 0.96);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ios-ctx-header {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios-ctx-btn {
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  text-align: left;
}

.ios-ctx-btn:last-child {
  border-bottom: none;
}

.ios-ctx-btn:hover,
.ios-ctx-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.ios-ctx-btn.destructive {
  color: #ff453a;
}

/* iOS Bottom Floating Undo Toast */
.ios-undo-toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(36, 36, 36, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
  z-index: 85;
  white-space: nowrap;
}

.btn-ios-undo {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

/* ==========================================================================
   Apple Dark Mode Sign-In Gate (#auth-gate)
   ========================================================================== */
.auth-gate {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 0%, #242424 0%, #171717 62%, #121212 100%);
  z-index: 100;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: rgba(32, 32, 32, 0.95);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px 20px 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.auth-logo {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  display: block;
}

.auth-title {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.auth-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-sec);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-sec);
}

.auth-input {
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 10px;
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-auth-primary {
  margin-top: 2px;
  width: 100%;
  border: 0;
  background: #f5f5f5;
  color: #121212;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.btn-auth-secondary {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.auth-restricted-box {
  background: var(--red-soft);
  border: 1px solid rgba(255, 69, 58, 0.35);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

.auth-restricted-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--red);
}

.auth-status-msg {
  font-size: 12px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-subtle);
  color: var(--text-sec);
  border: 1px solid var(--border);
}

.auth-status-msg.error {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(255, 69, 58, 0.35);
}

.auth-status-msg.ok {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(48, 209, 88, 0.35);
}
