/* Custom styles — Pico CSS handles most things */

/* --- Theme tokens ---
   Defaults below preserve the original look. Individual themes in
   themes.css override these (and the underlying --pico-* variables)
   when :root carries a matching data-style="<slug>" attribute. */
:root {
  /* Typography hooks (unset = inherit Pico defaults) */
  --theme-font-body: inherit;
  --theme-font-heading: inherit;
  --theme-heading-weight: inherit;
  --theme-heading-tracking: normal;
  --theme-heading-transform: none;

  /* Surface treatment hooks */
  --theme-radius-card: var(--pico-border-radius);
  --theme-radius-pill: 1rem;
  --theme-shadow-card: none;
  --theme-nav-link-radius: 0;
  --theme-nav-link-transform: none;
  --theme-nav-link-tracking: normal;

  /* Status / utility colors */
  --theme-badge-bg: rgba(244, 67, 54, 0.8);
  --theme-badge-fg: #fff;
  --theme-error-bg: #d32f2f;
  --theme-error-fg: #fff;
  --theme-status-info-bg: rgba(100, 149, 237, 0.12);
  --theme-status-info-border: rgba(100, 149, 237, 0.4);
  --theme-status-success-bg: rgba(60, 160, 80, 0.12);
  --theme-status-success-border: rgba(60, 160, 80, 0.5);
  --theme-status-warn-bg: rgba(230, 170, 50, 0.12);
  --theme-status-warn-border: rgba(230, 170, 50, 0.5);
  --theme-status-error-bg: rgba(210, 60, 60, 0.12);
  --theme-status-error-border: rgba(210, 60, 60, 0.5);

  /* Chat copy-button (light = bubble on dark surface, dark = on light) */
  --theme-copy-btn-light-bg: rgba(255, 255, 255, 0.15);
  --theme-copy-btn-light-bg-hover: rgba(255, 255, 255, 0.25);
  --theme-copy-btn-light-border: rgba(255, 255, 255, 0.25);
  --theme-copy-btn-dark-bg: rgba(0, 0, 0, 0.1);
  --theme-copy-btn-dark-bg-hover: rgba(0, 0, 0, 0.2);
  --theme-copy-btn-dark-border: rgba(0, 0, 0, 0.15);
}

body {
  font-family: var(--theme-font-body, inherit);
}
h1, h2, h3, h4, h5, h6 {
  font-family: var(--theme-font-heading, inherit);
  font-weight: var(--theme-heading-weight, inherit);
  letter-spacing: var(--theme-heading-tracking, normal);
  text-transform: var(--theme-heading-transform, none);
}

/* Accessibility helper for the nav theme switcher label. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- User nav --- */
.user-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.user-display-name {
  opacity: 0.7;
}
.logout-link {
  font-size: 0.8rem;
  opacity: 0.6;
}
.logout-link:hover {
  opacity: 1;
}

/* --- Environment badge --- */
.env-badge {
  display: inline-block;
  background: var(--theme-badge-bg);
  color: var(--theme-badge-fg);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  vertical-align: super;
  letter-spacing: 0.05em;
}

/* --- Theme switcher (nav) --- */
.theme-switcher-li select,
select#theme-switcher {
  margin: 0;
  padding: 0.2rem 1.75rem 0.2rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.2;
  height: auto;
  width: auto;
  min-width: 0;
  background-position: right 0.4rem center;
}
.login-theme-switcher {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 0.5rem;
}
.login-theme-switcher select {
  margin: 0;
  padding: 0.2rem 1.75rem 0.2rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.2;
  height: auto;
  width: auto;
  background-position: right 0.4rem center;
}

/* --- Dashboard --- */
.stat-card {
  text-align: center;
  padding: 1rem;
}
.stat-card small {
  display: block;
  opacity: 0.7;
  margin-bottom: 0.25rem;
}
.stat-card strong {
  font-size: 1.75rem;
}
.chart-wrap {
  position: relative;
  height: 260px;
}
.chart-wrap-tall {
  height: 600px;
}

/* --- Focus Block --- */
.focus-card {
  margin-bottom: 1rem;
  border-radius: var(--theme-radius-card, var(--pico-border-radius));
  box-shadow: var(--theme-shadow-card, none);
}
.focus-card header {
  margin-bottom: 0.25rem;
}
.focus-card p {
  margin-bottom: 0.5rem;
}
.focus-techniques {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.focus-techniques span {
  display: inline-block;
  background: var(--pico-primary-focus);
  color: var(--pico-color);
  font-size: 0.78rem;
  padding: 0.15rem 0.55rem;
  border-radius: 1rem;
  line-height: 1.4;
}
.focus-meta {
  font-size: 0.85rem;
  opacity: 0.65;
  margin-bottom: 0.5rem;
}
.focus-card progress {
  margin-bottom: 0.5rem;
}
.focus-empty {
  text-align: center;
  padding: 0.5rem 0;
}
.focus-empty p {
  opacity: 0.6;
  margin-bottom: 0.75rem;
}

/* --- Panel dropdown --- */
.panel-dropdown ul {
  min-width: 14rem;
}
.panel-dropdown li {
  padding: 0.25rem 0.75rem;
}
.panel-dropdown label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  margin: 0;
}
.panel-dropdown input[type="checkbox"] {
  margin: 0;
}

/* --- Notes --- */
.notes-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.notes-toolbar hgroup {
  margin-bottom: 0;
}
.notes-toolbar hgroup p {
  margin-bottom: 0;
}
.notes-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 220px);
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
.notes-controls label {
  margin-bottom: 0;
}
.note-search {
  margin-bottom: 0;
}
.note-sort {
  margin-bottom: 0;
}
.note-results-count {
  opacity: 0.7;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--theme-radius-card, var(--pico-border-radius));
  overflow: hidden;
  box-shadow: var(--theme-shadow-card, none);
}
.note-row + .note-row {
  border-top: 1px solid var(--pico-muted-border-color);
}
.note-row-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  color: inherit;
}
.note-row-link:hover,
.note-row-link:focus-visible {
  background: var(--pico-secondary-background, rgba(127, 127, 127, 0.08));
  text-decoration: none;
}
.note-row-title {
  font-weight: 600;
  color: var(--pico-primary);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-row-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  font-size: 0.8rem;
  opacity: 0.75;
}
.note-row-source {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
}
.note-empty {
  text-align: center;
}
.note-empty h2 {
  margin-bottom: 0.5rem;
}
.note-detail-card {
  margin-bottom: 1rem;
}
.note-date-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}
.note-date-list p {
  margin-bottom: 0;
}
.note-rendered > *:first-child {
  margin-top: 0;
}
.note-rendered > *:last-child {
  margin-bottom: 0;
}
.note-empty-copy {
  opacity: 0.7;
  font-style: italic;
}
.note-editor {
  min-height: 22rem;
  resize: vertical;
}
.note-page-actions,
.note-form-actions {
  gap: 0.75rem;
}

/* --- Chat --- */
/* Keep the chat page using the same container width as the rest of
   the app; only collapse the vertical padding so the chat message
   list can fill most of the viewport. */
body[data-page="chat"] main.container {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}
body[data-page="chat"] footer.container {
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}
.chat-page {
  display: flex;
  flex-direction: column;
  /* Fill almost the entire viewport minus nav and a small footer. */
  height: calc(100vh - 6.5rem);
  min-height: 24rem;
  margin: 0;
}
.chat-page h1 {
  flex: 0 0 auto;
  margin: 0 0 0.5rem;
}
.chat-page #chat-form {
  flex: 0 0 auto;
  margin-bottom: 0;
}
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--theme-radius-card, var(--pico-border-radius));
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--theme-shadow-card, none);
}

.chat-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  max-width: 80%;
  word-wrap: break-word;
  position: relative;
}

.chat-user {
  align-self: flex-end;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  white-space: pre-wrap;
}

.chat-assistant {
  align-self: flex-start;
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}

.chat-assistant p,
.chat-assistant ul,
.chat-assistant ol,
.chat-assistant table,
.chat-assistant h1,
.chat-assistant h2,
.chat-assistant h3,
.chat-assistant h4 {
  margin-top: 0;
  margin-bottom: 0.25rem;
  padding: 0;
}

.chat-assistant h2,
.chat-assistant h3,
.chat-assistant h4 {
  font-size: 1rem;
  margin-top: 0.5rem;
}

.chat-assistant ul,
.chat-assistant ol {
  padding-left: 1.25rem;
}

.chat-assistant li {
  margin-bottom: 0.15rem;
}

.chat-assistant *:last-child {
  margin-bottom: 0;
}

.chat-timing {
  display: block;
  opacity: 0.45;
  font-size: 0.75rem;
  margin-top: 0.35rem;
  font-style: italic;
}

.copy-btn {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: var(--theme-copy-btn-light-bg);
  border: 1px solid var(--theme-copy-btn-light-border);
  border-radius: 0.35rem;
  padding: 0.2rem 0.35rem;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s ease, background 0.2s ease;
  margin: 0;
  min-height: 0;
  color: inherit;
}

.copy-btn svg {
  display: block;
  pointer-events: none;
}

.copy-btn:hover {
  opacity: 1;
  background: var(--theme-copy-btn-light-bg-hover);
}

.copy-btn:focus {
  opacity: 1;
  outline: 2px solid var(--pico-primary);
  outline-offset: 2px;
}

.chat-assistant .copy-btn {
  background: var(--theme-copy-btn-dark-bg);
  border-color: var(--theme-copy-btn-dark-border);
}

.chat-assistant .copy-btn:hover {
  background: var(--theme-copy-btn-dark-bg-hover);
}

.round-row {
  margin-bottom: 0.5rem;
}

.round-remove {
  max-width: 3rem;
  padding: 0.25rem 0.5rem;
  align-self: center;
}

/* Dialog sizing */
dialog article {
  max-width: 700px;
}

dialog pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 400px;
  overflow-y: auto;
}

#chat-form #history-months {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
}

#chat-form #persona-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  max-width: 8rem;
}

/* --- Error banner --- */
.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--theme-error-bg);
  color: var(--theme-error-fg);
  padding: 0.65rem 1rem;
  border-radius: var(--theme-radius-card, var(--pico-border-radius));
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  animation: fadeIn 0.2s ease;
  box-shadow: var(--theme-shadow-card, none);
}
.error-banner .error-close {
  background: none;
  border: none;
  color: var(--theme-error-fg);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0.8;
  margin: 0;
}
.error-banner .error-close:hover {
  opacity: 1;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-0.25rem); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Backup-to-Drive status messages --- */
.backup-status {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  line-height: 1.4;
}
.backup-status-info {
  background: var(--theme-status-info-bg);
  border: 1px solid var(--theme-status-info-border);
}
.backup-status-success {
  background: var(--theme-status-success-bg);
  border: 1px solid var(--theme-status-success-border);
}
.backup-status-warn {
  background: var(--theme-status-warn-bg);
  border: 1px solid var(--theme-status-warn-border);
}
.backup-status-error {
  background: var(--theme-status-error-bg);
  border: 1px solid var(--theme-status-error-border);
}

/* --- Login page --- */
.login-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.login-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem 1.5rem;
}
.login-card {
  width: min(100%, 30rem);
  margin: 0;
  text-align: center;
  border-radius: var(--theme-radius-card, var(--pico-border-radius));
  box-shadow: var(--theme-shadow-card, none);
}
.login-header {
  margin-bottom: 1.5rem;
}
.login-header p:last-child {
  opacity: 0.72;
  margin-bottom: 0;
}
.login-actions {
  display: grid;
  gap: 1rem;
}
.provider-button {
  margin-bottom: 0;
}
.login-separator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--pico-muted-color);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.login-separator::before,
.login-separator::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--pico-muted-border-color);
}
.login-footer {
  padding-bottom: 1.5rem;
  text-align: center;
}
.login-footer small {
  opacity: 0.5;
}

/* --- Mobile improvements --- */
@media (max-width: 768px) {
  nav.container {
    flex-wrap: wrap;
  }
  nav ul {
    flex-wrap: wrap;
    gap: 0.15rem 0.5rem;
    white-space: normal;
  }
  nav ul li a {
    font-size: 0.85rem;
    padding: 0.25rem 0.4rem;
  }
  .chat-page {
    /* Don't try to break out of the container on small screens. */
    width: auto;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    height: auto;
  }
  .chat-messages {
    max-height: 60vh;
  }
}

@media (max-width: 576px) {
  .login-shell {
    padding-top: 2rem;
  }
  .round-row .grid {
    grid-template-columns: 1fr 1fr;
  }
  #add-round-btn,
  #add-technique-btn,
  #submit-btn,
  #note-submit-btn {
    min-height: 3rem;
    font-size: 1rem;
  }
  .notes-toolbar {
    align-items: stretch;
  }
  .notes-controls {
    grid-template-columns: 1fr;
  }
  .note-row-link {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  .note-row-title {
    white-space: normal;
  }
  .note-row-meta {
    gap: 0.5rem;
  }
  .note-page-actions,
  .note-form-actions {
    grid-template-columns: 1fr;
  }
  .stat-card strong {
    font-size: 1.4rem;
  }
  .chart-wrap {
    height: 220px;
  }
}
