/* PIP-OS layout — responsive shell, square on landscape desktop */

/* position:fixed + inset:0 sizes against the layout viewport on mobile
   Safari, which can leave a gap below the toolbar showing body's
   background. A normal-flow block sized to its parent avoids that. */
#letterbox {
  position: relative;
  height: 100%;
  min-height: 100svh;
  min-height: -webkit-fill-available;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

/* Gutter decorations — landscape desktop only */
#gutter-l, #gutter-r {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2rem;
  color: var(--border);
  font-size: var(--fs-sm);
  pointer-events: none;
  user-select: none;
  white-space: pre;
  overflow: hidden;
  max-height: 100dvh;
  display: none;
}

/* Mobile-first: fill the full screen */
#app-shell {
  width: 100%;
  height: 100%;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  container-type: size;
  container-name: shell;
  /* PWA standalone mode draws content under the notch — pad it back in.
     Bottom padding is a small fixed value (not env(safe-area-inset-bottom)) so the
     bottom nav clears the home-indicator/rounded-corner area without leaving a large
     gap — it's covered by #app-shell's own background and the FX overlays above it,
     so it stays invisible in every theme. */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(8px * var(--ui-scale));
}

/* Landscape desktop (wider than tall): square letterbox */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) {
  #letterbox { align-items: center; }
  #gutter-l, #gutter-r { display: flex; }
  #app-shell {
    width: min(100vw, 100dvh);
    height: min(100vw, 100dvh);
  }
}

/* Tab bar — top inside square */
#tab-bar {
  display: flex;
  flex-shrink: 0;
  height: var(--tab-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-color);
  user-select: none;
  letter-spacing: 0.05em;
}
.tab-btn:last-child { border-right: none; }
.tab-btn:hover:not(.active) { color: var(--bright); }
.tab-btn.active {
  background: var(--fg);
  color: var(--bg);
  font-weight: bold;
}

/* Page container */
#page-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.page.active { display: flex; }

/* Status bar — bottom of shell */
#status-bar {
  height: var(--status-h);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: var(--fs-sm);
  color: var(--dim);
  flex-shrink: 0;
  gap: 8px;
}
#status-bar .status-time { margin-left: auto; }
#status-bar #home-btn,
#status-bar #status-nav button {
  color: var(--fg);
  border-color: var(--fg);
  font-weight: bold;
  letter-spacing: 0.05em;
}
#status-bar #home-btn { padding: 0 7px; flex-shrink: 0; display: none; }

/* Quick-nav buttons — inline in status bar, mobile only */
#status-bar #status-nav { display: none; gap: 4px; flex-shrink: 0; }

#bottom-tabs {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* Phone: hide top tab bar — status bar becomes a full row of nav buttons */
@media (max-width: 600px) {
  #tab-bar { display: none; }
  #status-bar { gap: 4px; padding: 0 4px; }
  #status-bar #home-btn { display: inline-block; flex: 1; padding: 0 2px; text-align: center; }
  #status-bar #status-nav { display: contents; }
  #status-bar #status-nav button { flex: 1; padding: 0 2px; text-align: center; }
  #status-bar #status-user,
  #status-bar #status-clock { display: none; }
}
#bottom-tabs .tab-btn { border-right: 1px solid var(--border); border-top: none; }

/* Two-column layout inside pages */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}
.two-col > * { overflow: hidden; }
.two-col .col-left { border-right: 1px solid var(--border); }

@container shell (max-width: 480px) {
  .two-col {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .two-col .col-left { border-right: none; border-bottom: 1px solid var(--border); }
}

/* 2x2 grid for dashboard */
.quad-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}
.quad-grid > .panel { overflow: hidden; }
.quad-grid > .panel:nth-child(1) { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.quad-grid > .panel:nth-child(2) { border-bottom: 1px solid var(--border); }
.quad-grid > .panel:nth-child(3) { border-right: 1px solid var(--border); }

/* quad-grid always stays 2×2 — panels scroll internally */

/* Vertical dashboard layout — fluid, content-fed home screen */
.dash-vertical {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.dash-header-row {
  display: flex;
  align-items: stretch;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.dash-col-clock, .dash-col-cal {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--panel-pad);
}
.dash-col-clock {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: 2px;
  padding-left: calc(var(--panel-pad) + 10px);
}
.dash-col-clock #clock-display, .dash-col-clock #date-display {
  text-align: left;
}
.dash-col-clock #weather-widget {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.dash-col-cal {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 1px solid var(--border);
}
.dash-col-cal .mini-cal {
  height: calc(100% - 8px);
  margin: 0;
  margin-top: auto;
  display: flex;
  flex-direction: column;
}
.dash-col-cal .mini-cal-hdr {
  flex: 0 0 auto;
}
.dash-col-cal .mini-cal-grid {
  flex: 1 1 auto;
  min-height: 0;
  grid-auto-rows: 1fr;
}
.dash-vertical #panel-feed { flex: 1 1 0; min-height: 0; }
.dash-notes-panel { flex: 1 1 0; min-height: 0; }
.dash-ekta-panel { flex: 1 1 0; min-height: 0; }

/* Quick-add dropdown menu (anchored near the triggering + button) */
.qa-dropdown {
  position: fixed;
  z-index: 950;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--fg);
  min-width: 9em;
}
.qa-dropdown button {
  background: none;
  border: none;
  color: var(--fg);
  text-align: left;
  padding: 6px 10px;
  font-size: var(--fs-sm);
  cursor: pointer;
  font-family: var(--font);
}
.qa-dropdown button:hover {
  background: var(--fg);
  color: var(--bg);
}
.qa-dropdown button + button {
  border-top: 1px solid var(--border);
}

/* Login / setup screen */
#auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  flex-direction: column;
}
#auth-screen.hidden { display: none; }

.auth-box {
  width: min(360px, 90vw);
  border: 1px solid var(--fg);
  padding: 1.5rem;
}
.auth-box h1 {
  font-size: var(--fs-lg);
  margin-bottom: 0.25rem;
  letter-spacing: 0.1em;
}
.auth-box .sub {
  color: var(--dim);
  font-size: var(--fs-sm);
  margin-bottom: 1.25rem;
}
.auth-box .field { margin-bottom: 0.75rem; }
.auth-box label { display: block; font-size: var(--fs-sm); color: var(--dim); margin-bottom: 2px; }
.auth-box input {
  padding: 6px 8px;
}
.auth-box .auth-actions { display: flex; gap: 8px; flex-direction: column; margin-top: 1rem; }
.auth-box .err { color: var(--fg); font-size: var(--fs-sm); margin-top: 0.5rem; border: 1px solid var(--fg); padding: 4px 8px; display: none; }
.auth-box .err.show { display: block; }

/* Page header strip */
.page-header {
  padding: 4px var(--panel-pad);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-header .ph-title { color: var(--bright); font-weight: bold; }
.page-header .ph-sub { color: var(--dim); }
.page-header .ph-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* Row items */
.item-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px var(--panel-pad);
  cursor: pointer;
  transition: var(--transition-color);
  border-bottom: 1px solid transparent;
  min-height: 28px;
}
.item-row:hover { background: rgba(var(--fg-rgb, 242,242,242), 0.07); }
.item-row.selected { background: var(--fg); color: var(--bg); }
.item-row.selected .btn.danger { border-color: var(--bg); }
.item-row .row-cursor { flex-shrink: 0; width: 12px; }
.item-row .row-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .row-meta { color: var(--dim); font-size: var(--fs-sm); flex-shrink: 0; }
.item-row.done .row-title { text-decoration: line-through; color: var(--dim); }

/* Section toggle */
.section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px var(--panel-pad);
  color: var(--dim);
  font-size: var(--fs-sm);
  cursor: pointer;
  border-top: 1px solid var(--border);
}
.section-toggle:hover { color: var(--fg); }

/* Scrollable content area */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Note reader / prose */
.prose {
  padding: 0.75rem 1rem;
  max-width: 66ch;
  line-height: 1.7;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.prose h1, .prose h2, .prose h3, .prose h4 {
  margin: 1em 0 0.4em;
  font-size: var(--fs);
  font-weight: bold;
}
.prose h1::before { content: '# '; color: var(--dim); }
.prose h2::before { content: '## '; color: var(--dim); }
.prose h3::before { content: '### '; color: var(--dim); }
.prose p { margin: 0.5em 0; }
.prose ul { padding-left: 1.5em; }
.prose ul li::before { content: '• '; }
.prose ol { padding-left: 1.5em; counter-reset: li; }
.prose ol li::before { counter-increment: li; content: counter(li) '. '; }
.prose strong { color: var(--bright); }
.prose em { font-style: normal; color: var(--dim); }
.prose code, .prose pre { font-family: var(--font); background: transparent; }
.prose pre { padding-left: 2ch; margin: 0.5em 0; white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere; }
.prose blockquote { border-left: 2px solid var(--border); padding-left: 1ch; color: var(--dim); }
.prose table { border-collapse: collapse; width: 100%; margin: 0.5em 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: 2px 6px; text-align: left; }
.prose th { color: var(--bright); }
.prose a { text-decoration: underline; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* Progress bar */
.pbar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
}
.pbar-track {
  flex: 1;
  height: 1em;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.pbar-fill {
  display: block;
  height: 100%;
  background: var(--fg);
  transition: width 0.3s;
}
.pbar-label { flex-shrink: 0; min-width: 4ch; text-align: right; }

/* Settings accordion */
.acc-section { border-bottom: 1px solid var(--border); }
.acc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px var(--panel-pad);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: bold;
  letter-spacing: 0.08em;
  transition: var(--transition-color);
}
.acc-head:hover { color: var(--bright); }
.acc-head .acc-arrow { transition: transform 0.15s; }
.acc-head.open .acc-arrow { transform: rotate(90deg); }
.acc-body {
  display: none;
  padding: 0.5rem var(--panel-pad) 0.75rem;
}
.acc-body.open { display: block; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: var(--fs-sm);
  gap: 8px;
}
.setting-row label { color: var(--dim); flex: 1; }

/* Clock digits */
#clock-display {
  font-size: clamp(1.2rem, 5cqw, 3rem);
  letter-spacing: 0.1em;
  font-weight: bold;
  text-align: center;
  padding: 0.25rem 0;
  text-shadow: var(--glow-text);
}
#date-display {
  text-align: center;
  color: var(--dim);
  font-size: var(--fs-sm);
}

/* Tag badges */
.tag-p { color: var(--fg); }
.tag-p::before { content: '[P] '; color: var(--dim); }
.tag-w { color: var(--fg); }
.tag-w::before { content: '[W] '; color: var(--dim); }

/* Timeline */
.timeline-day {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: 8px var(--panel-pad) 4px;
  margin-top: 2px;
  color: var(--dim);
  font-size: var(--fs-sm);
  border-top: 1px solid var(--border);
}
.timeline-day:first-child {
  margin-top: 0;
  border-top: none;
}
.timeline-day.is-today {
  color: var(--bright);
  border-top-color: var(--fg);
}

/* Timeline sections — past / today / upcoming */
.timeline-section-hdr {
  padding: 6px var(--panel-pad) 2px;
  font-size: var(--fs-sm);
  letter-spacing: 0.2em;
  text-align: center;
}
.timeline-section.timeline-past { opacity: 0.55; }
.timeline-section.timeline-today {
  border: 1px solid var(--fg);
  margin: 6px var(--panel-pad);
}
.timeline-section.timeline-today .timeline-day {
  position: static;
  border-top: none;
}

/* File type glyphs */
.ftype { flex-shrink: 0; }

/* Priority badges */
.prio-1::after { content: ' !'; color: var(--dim); }
.prio-2::after { content: ' !!'; color: var(--fg); }

/* Read-only badge */
.readonly-badge {
  font-size: var(--fs-sm);
  color: var(--dim);
  border: 1px solid var(--border);
  padding: 0 6px;
}

/* Checkbox */
.chk {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15em;
  cursor: pointer;
  text-align: center;
}
