/* Sally HQ - dark theme - mobile-first responsive */
:root {
  --bg: #0e0f13;
  --bg2: #161821;
  --bg3: #1f2230;
  --fg: #e8eaed;
  --muted: #8b8f9c;
  --accent: #ff6b9d;
  --accent2: #7aa2f7;
  --good: #9ece6a;
  --warn: #e0af68;
  --bad: #f7768e;
  --border: #2a2e3e;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  font-size: 16px;
  -webkit-tap-highlight-color: rgba(255,107,157,0.2);
}

/* ============ NAV ============ */
nav {
  background: var(--bg2);
  padding: 10px 16px;
  display: flex;
  gap: 6px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
nav a {
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
nav a:hover, nav a:active { background: var(--bg3); }
nav a.brand {
  font-weight: 700;
  color: var(--accent);
  font-size: 16px;
  margin-right: auto;
}
.nav-links { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav-links a.logout { color: var(--muted); margin-left: 6px; }

.nav-toggle { display: none; }
.burger { display: none; }
.nav-overlay { display: none; }

@media (max-width: 720px) {
  .burger {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 22px;
    cursor: pointer;
    padding: 0;
    z-index: 102;
    position: relative;
  }
  .burger span {
    display: block;
    height: 3px;
    width: 100%;
    background: var(--fg);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.2s;
    transform-origin: center;
  }
  .nav-toggle:checked ~ .burger span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
  .nav-toggle:checked ~ .burger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .burger span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }

  .nav-links {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(78vw, 320px);
    background: var(--bg2);
    border-left: 1px solid var(--border);
    flex-direction: column;
    gap: 4px;
    padding: 70px 16px max(24px, env(safe-area-inset-bottom)) 16px;
    align-items: stretch;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 101;
    box-shadow: -10px 0 30px rgba(0,0,0,0.4);
    overflow-y: auto;
  }
  .nav-links a { padding: 14px 16px; font-size: 16px; border-radius: 10px; }
  .nav-links a.logout {
    margin-left: 0;
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 18px;
    border-radius: 0;
  }
  .nav-toggle:checked ~ .nav-links { transform: translateX(0); }

  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
  }
  .nav-toggle:checked ~ .nav-overlay { opacity: 1; pointer-events: auto; }

  body:has(.nav-toggle:checked) { overflow: hidden; }
}

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
h1 { margin: 0 0 12px; font-size: 24px; }
h2 { margin-top: 28px; border-bottom: 1px solid var(--border); padding-bottom: 6px; font-size: 18px; }
h3 { font-size: 16px; }
a { color: var(--accent2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); }
.ts {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ============ TABLES ============ */
.table-wrap, table { -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 12px;
  font-size: 14px;
}
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  background: var(--bg3);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
tr:last-child td { border-bottom: none; }

/* On mobile, wrap tables in scroll containers via overflow */
@media (max-width: 720px) {
  table { display: block; overflow-x: auto; white-space: nowrap; }
  td.muted.small { white-space: normal; max-width: 200px; }
  th, td { padding: 8px 10px; }
}

/* ============ STATS CARDS ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.1s, border-color 0.1s;
}
.card:hover, .card:active { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { margin: 0; font-size: 26px; color: var(--accent); }
.card p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card.big { grid-column: span 2; }
@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card.big { grid-column: span 2; }
  .card h3 { font-size: 22px; }
}

/* ============ TAGS ============ */
.tag {
  display: inline-block;
  background: var(--bg3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--muted);
}
.tag-chat { background: #2d3a52; color: #7aa2f7; }
.tag-cron_run { background: #3a2d52; color: #bb9af7; }
.tag-subagent { background: #523a2d; color: #e0af68; }
.tag-tool_call { background: #2d5240; color: #9ece6a; }
.tag-note { background: #523a52; color: #ff6b9d; }
.tag-done { background: #2d5240; color: #9ece6a; }
.tag-failed { background: #523a3a; color: #f7768e; }
.tag-running { background: #2d3a52; color: #7aa2f7; }

/* ============ FILTERS ============ */
.filters { margin: 12px 0; display: flex; gap: 6px; flex-wrap: wrap; }
.filters a {
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg2);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}
.filters a.active { background: var(--accent); color: white; }

/* ============ FORMS ============ */
form input, form textarea, form select, form button {
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 16px; /* >= 16px prevents iOS zoom on focus */
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
form input:focus, form textarea:focus, form select:focus {
  outline: none;
  border-color: var(--accent);
}
form textarea { width: 100%; min-height: 80px; resize: vertical; }
form button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 44px; /* touch target */
}
form button:hover, form button:active { background: #ff5089; }
form button.danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--bad);
}
form button.danger:hover, form button.danger:active { background: var(--bad); color: white; }
form button.small { padding: 6px 12px; font-size: 13px; min-height: 32px; }

.add-form {
  margin: 14px 0;
  background: var(--bg2);
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.add-form summary {
  cursor: pointer;
  padding: 6px 0;
  color: var(--accent);
  font-weight: 600;
  user-select: none;
}
.add-form form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.add-form form .row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-form form .row > * { flex: 1 1 140px; min-width: 0; }
@media (max-width: 480px) {
  .add-form form .row { flex-direction: column; gap: 8px; }
  .add-form form .row > * { width: 100%; }
}

.search-bar {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.search-bar input { flex: 1 1 200px; min-width: 0; }
.search-bar select { flex: 0 1 180px; }
.search-bar button { flex: 0 0 auto; }
@media (max-width: 480px) {
  .search-bar { flex-direction: column; }
  .search-bar input, .search-bar select, .search-bar button { width: 100%; }
}

/* ============ LOGIN ============ */
.login-box {
  max-width: 360px;
  margin: 60px auto;
  background: var(--bg2);
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.login-box h1 { text-align: center; color: var(--accent); margin-top: 0; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 480px) {
  .login-box { margin: 20px auto; padding: 20px; }
}

/* ============ NOTES / RESTAURANTS / generic card grids ============ */
.notes-grid, .cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.restaurant-card, .note-card {
  background: var(--bg2);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.rc-head, .nc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.rc-head h3, .nc-head h3 { margin: 0; }
.rating {
  background: var(--accent);
  color: white;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}
.note-body {
  background: var(--bg);
  padding: 10px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 13px;
  max-height: 200px;
  overflow: auto;
}
.rc-foot { margin-top: 8px; }

/* ============ PLACES ============ */
.page-head { margin-bottom: 12px; }
.places-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
@media (max-width: 480px) {
  .places-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}
.place-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  transition: transform 0.1s, border-color 0.1s;
}
.place-card:hover, .place-card:active { transform: translateY(-3px); border-color: var(--accent); }
.pc-photo {
  position: relative;
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, var(--bg3), var(--bg));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pc-photo img { width: 100%; height: 100%; object-fit: cover; }
.pc-no-photo { font-size: 48px; opacity: 0.3; }
.pc-no-photo.big { font-size: 96px; }
.pc-cat {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pc-body {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pc-body h3 { margin: 0; font-size: 15px; line-height: 1.3; }
.pc-stats {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.pc-stats span { white-space: nowrap; }
@media (max-width: 480px) {
  .pc-body { padding: 10px; }
  .pc-body h3 { font-size: 14px; }
  .pc-stats { font-size: 11px; gap: 8px; }
}

/* ============ PLACE DETAIL ============ */
.place-detail {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.pd-hero {
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--bg3), var(--bg));
  display: flex;
  align-items: center;
  justify-content: center;
}
.pd-hero img { width: 100%; height: 100%; object-fit: cover; }
.pd-info h1 { margin: 0 0 8px; }
.pd-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.pd-stats > div {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.pd-stats strong { font-size: 20px; color: var(--accent); }
.pd-stats span {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
@media (max-width: 720px) {
  .place-detail { grid-template-columns: 1fr; gap: 14px; }
  .pd-hero { aspect-ratio: 16 / 9; max-height: 220px; }
}

/* ============ MISC ============ */
.visits-table th, .visits-table td { font-size: 13px; }
@media (max-width: 480px) {
  main { padding: 12px; }
  h1 { font-size: 22px; }
  h2 { font-size: 16px; }
  .add-form { padding: 10px 12px; }
}

/* Safe area for iOS notch */
@supports (padding: max(0px)) {
  nav { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  main {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ============ NOTES APP (two-pane) ============ */
.notes-app {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  height: calc(100vh - 100px);
  min-height: 500px;
}
.notes-sidebar {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.notes-head h1 { margin: 0; font-size: 20px; }
.new-note-btn { margin: 0; }
.new-note-btn button {
  width: 36px; height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  border-radius: 50%;
  min-height: 0;
}

.notes-tabs {
  display: flex;
  padding: 8px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
.notes-tabs a {
  flex: 1;
  padding: 8px 6px;
  text-align: center;
  font-size: 13px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}
.notes-tabs a span {
  font-size: 11px;
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 4px;
}
.notes-tabs a.active { background: var(--bg3); color: var(--fg); }
.notes-tabs a.active span { background: var(--accent); color: white; }

.notes-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.notes-search input { width: 100%; }

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.notes-list li {
  border-bottom: 1px solid var(--border);
}
.notes-list li.empty { padding: 20px; text-align: center; }
.notes-list a {
  display: block;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--fg);
}
.notes-list a:hover { background: var(--bg3); }
.notes-list li.selected a {
  background: var(--bg3);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.nl-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; margin-bottom: 4px;
}
.nl-title strong {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.nl-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.nl-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg3);
}
.badge-sally { background: #523a52; color: #ff6b9d; }
.badge-danny { background: #2d3a52; color: #7aa2f7; }

.notes-pane {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pane-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.pane-meta { flex: 1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pane-head .back-btn {
  display: none;
  color: var(--accent2);
  text-decoration: none;
  font-size: 14px;
}
.pane-head form.inline { margin: 0; }

.note-editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px;
  gap: 10px;
  overflow: hidden;
}
.note-editor .row { display: flex; gap: 10px; }
.note-editor .row > * { flex: 1; }
.note-title {
  font-size: 22px;
  font-weight: 700;
  background: transparent;
  border: none;
  padding: 6px 0;
  color: var(--fg);
}
.note-title:focus { border-bottom: 2px solid var(--accent); border-radius: 0; }
.note-body-edit {
  flex: 1;
  resize: none;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  min-height: 200px;
}
.editor-actions { display: flex; align-items: center; gap: 12px; }

.pane-empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  text-align: center;
}

/* Mobile: stack panes, show only one at a time */
@media (max-width: 720px) {
  .notes-app {
    grid-template-columns: 1fr;
    height: calc(100vh - 90px);
  }
  .notes-app[data-open="1"] .notes-sidebar { display: none; }
  .notes-app[data-open="0"] .notes-pane { display: none; }
  .pane-head .back-btn { display: inline-block; }
  .note-title { font-size: 18px; }
  .note-editor .row { flex-direction: column; gap: 8px; }
}
