/* PandaDays — mobile-first base styles */
:root {
  --bg: #f7f7f5;
  --fg: #1f2328;
  --muted: #6b7280;
  --surface: #ffffff;
  --border: #e5e7eb;
  --control-border: #858b94;
  --accent: #276749;
  --on-accent: #ffffff;
  --focus: #276749;
  --radius: 12px;
  --space: 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111315;
    --fg: #e6e6e6;
    --muted: #9ca3af;
    --surface: #1b1e21;
    --border: #2d3135;
    --control-border: #6b7280;
    --accent: #68d391;
    --on-accent: #111315;
    --focus: #68d391;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
#main:focus { outline: none; }

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -10rem;
  z-index: 10;
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.skip-link:focus { top: 0.5rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

img, video, audio { max-width: 100%; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem var(--space);
  padding: 0.75rem var(--space);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--fg);
  text-decoration: none;
}

.avatar-notification { position: relative; display: inline-flex; flex-shrink: 0; overflow: visible !important; }
.notification-badge { position: absolute; top: -0.5rem; right: -0.625rem; min-width: 1.25rem; padding: 0 0.25rem; border-radius: 1rem 1rem 1rem 0; background: #b42318; color: #fff; text-align: center; font-size: 0.75rem; font-weight: 700; }
.message-list { list-style: none; padding: 0; margin: 0; }
.message-list .hint { overflow-wrap: anywhere; }

.container {
  width: 100%;
  padding: var(--space);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space);
}

.btn {
  display: inline-block;
  min-height: 44px;
  padding: 0.625rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  cursor: pointer;
}

.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-secondary { background: var(--surface); color: var(--accent); border: 1px solid var(--control-border); }
.danger-text { color: #c53030; }
:root[data-theme="dark"] .danger-text { color: #fca5a5; }

.empty { min-height: 40vh; }

.tagline { color: var(--muted); }

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem 0.75rem;
  font-size: 0.9375rem;
}

.nav-user { color: var(--muted); }

.page-heading, .page-actions, .search-controls, .admin-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.page-heading { justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.page-heading h1 { margin: 0; }
.page-actions { flex-wrap: wrap; }
.page-actions form { margin: 0; }
.header-controls, .header-toggles { display: flex; align-items: center; gap: 0.5rem; }
.header-controls { flex-wrap: wrap; justify-content: flex-end; }
.header-toggles form { margin: 0; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; color: var(--fg); background: var(--surface); cursor: pointer; text-decoration: none; font: inherit; flex-shrink: 0; }
.icon-button.btn { color: var(--on-accent); background: var(--accent); }
.theme-dark, :root[data-theme="dark"] .theme-light { display: none; }
:root[data-theme="dark"] .theme-dark { display: block; }
.users-toolbar { display: flex; align-items: center; gap: 0.75rem; }
.search-bar { flex: 1; min-width: 0; margin: 0; }
.search-field { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.75rem; border: 1px solid var(--control-border); border-radius: 8px; background: var(--surface); color: var(--muted); }
.search-field:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.search-field input { width: 100%; min-width: 0; min-height: 44px; border: 0; padding: 0.5rem 0; background: transparent; color: var(--fg); font: inherit; }
.search-field input:focus-visible { outline: none; }
.search-field input::placeholder { color: var(--muted); opacity: 1; }
.header-toggles .icon-button { border: 0; background: transparent; }
.header-search-menu[open] > summary { display: none; }
.header-search-menu > .header-search {
  display: flex;
  align-items: center;
  width: min(18rem, calc(100vw - 8.5rem));
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
}
.header-search .search-field { flex: 1; min-width: 0; border: 0; }
.header-search .search-field:focus-within { outline: none; }
.search-controls input { flex: 1; min-width: 0; }
.admin-list { list-style: none; padding: 0; display: grid; gap: 0.75rem; }
.admin-row { position: relative; justify-content: space-between; align-items: center; padding: 0.5rem 0.75rem; }
.admin-row:has(.dropdown[open]) { z-index: 2; }
.user-row-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 0.75rem; align-items: center; flex: 1; min-width: 0; text-decoration: none; color: var(--fg); }
.user-row-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.user-row-link:hover strong { text-decoration: underline; }
.user-actions { z-index: 1; }
.user-names { min-width: 0; display: flex; flex-wrap: wrap; gap: 0 0.75rem; overflow-wrap: anywhere; }
.user-created, .user-days { color: var(--muted); font-size: 0.8125rem; grid-column: 1; }
.user-row-link > .badge { grid-column: 2; grid-row: 1 / 4; }
.profile-details { display: grid; grid-template-columns: minmax(6rem, 1fr) minmax(0, 3fr); gap: 0.75rem 1rem; margin: 0; }
.profile-details dt { color: var(--muted); }
.profile-details dd { margin: 0; overflow-wrap: anywhere; }
.profile-comment { white-space: pre-wrap; }
.confirm-dialog { width: min(36rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; color: var(--fg); }
.confirm-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog.confirm-dialog { margin: auto; }
.confirm-dialog h2 { margin-top: 0; }
.confirm-dialog > .hint, .confirm-dialog > .alert { margin-top: 1rem; }
.dialog-actions { justify-content: flex-end; margin: 1rem 0 0; }
.password-row { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.password-row { justify-content: space-between; }
.password-mask { display: block; letter-spacing: 0.15em; }
.settings-card h2 { margin-top: 0; font-size: 1.125rem; }
.settings-card h3 { margin: 1.25rem 0 0.5rem; font-size: 1rem; }
.settings-card progress { width: 100%; }
.profile-card .password-row { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--control-border); }
.profile-layout { display: grid; gap: 1.25rem; justify-items: center; }
.profile-fields { display: grid; gap: var(--space); width: 100%; min-width: 0; }
.form .profile-fields input[readonly] { color: var(--muted); background: transparent; border-style: dashed; cursor: default; }
.avatar-box {
  display: grid;
  place-items: center;
  width: 10rem;
  aspect-ratio: 1;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--surface);
}
.avatar-editor { min-width: 0; }
.avatar-editor > summary { display: grid; cursor: pointer; list-style: none; }
.avatar-editor > summary::-webkit-details-marker { display: none; }
.avatar-editor > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.avatar-editor > [data-avatar-controls] { margin-top: 1rem; }
.avatar-circle { display: block; width: 7.5rem; height: 7.5rem; overflow: hidden; border-radius: 50%; }
.avatar-circle .avatar, .avatar-circle img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar-editor > summary:hover .avatar-circle { opacity: 0.85; }
@media (min-width: 600px) {
  .profile-layout { grid-template-columns: auto minmax(0, 1fr); align-items: start; justify-items: stretch; gap: 1.5rem; }
}
.link-button:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }
@media (min-width: 720px) {
  .user-row-link { grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 1rem; }
  .user-created, .user-days { grid-column: auto; }
  .user-row-link > .badge { grid-column: auto; grid-row: auto; }
}
.admin-row h2 { font-size: 1.125rem; }
.row-main { min-width: 0; }
.row-main .hint { margin-bottom: 0; }
.profile-identity { overflow-wrap: anywhere; }
.dropdown { position: relative; flex-shrink: 0; }
.dropdown > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem;
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.account-menu summary span { max-width: 12rem; overflow-wrap: anywhere; }
.avatar { width: 32px; height: 32px; flex-shrink: 0; color: var(--accent); border-radius: 50%; object-fit: cover; }
.dots { min-width: 44px; justify-content: center; font-size: 1.25rem; font-weight: 700; }
.dropdown-panel {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
  min-width: 11rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px #0002;
}
.dropdown-panel a, .dropdown-panel button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.625rem;
  text-align: left;
}
.dropdown-panel form { margin: 0; }
.dropdown-panel a:hover, .dropdown-panel button:hover { background: var(--bg); }

.admin-users { display: grid; gap: 1rem; margin-top: 1rem; }
.admin-users > .card { min-width: 0; }
.admin-identity { overflow-wrap: anywhere; margin: 0; }
.backup-entry + .backup-entry { border-top: 1px solid var(--border); padding-top: 1rem; }

@media (min-width: 720px) {
  .admin-users { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.inline-form { display: inline; margin: 0; }

.link-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.auth-card { max-width: 420px; margin: 1rem auto; }

.auth-card h1 { margin-top: 0; font-size: 1.375rem; }

.form { display: grid; gap: 0.875rem; }

.form label { display: grid; gap: 0.25rem; font-weight: 500; }

.form input[type="text"],
.form input[type="search"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form input[type="date"],
.form input[type="time"],
.form select,
.form textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
}

.form textarea { resize: vertical; }

.form label .hint { font-weight: 400; }

.form .icon-input { max-width: 8rem; }

.field-row { display: grid; gap: 0.875rem; }
.form .field-row label { align-content: start; }

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.choice-group legend { padding: 0; margin-bottom: 0.25rem; font-weight: 500; }
.choice-group > .hint, .choice-group > .color-row, .choice-group > label:not(.chip-check) { flex-basis: 100%; }

.form label.chip-check, .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 44px;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-weight: 400;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.form label.chip-check:has(input:checked) { border-color: var(--accent); }
.chip-check input { width: 1.125rem; height: 1.125rem; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 0.375rem; }

.tag-field > .tag-editor, .tag-field > [data-tag-fallback] { flex-basis: 100%; }
.tag-editor { display: flex; flex-direction: column; min-width: 0; padding: 0.625rem; border: 1px solid var(--control-border); border-radius: 12px; background: var(--bg); }
.tag-editor [data-tag-query-label] { order: 1; }
.tag-editor .tag-suggestions, .tag-editor [data-tag-empty] { order: 2; }
.tag-query-label { flex-basis: 100%; min-width: 0; }
.tag-editor:focus-within { border-color: var(--accent); }
.tag-editor:has(textarea:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.tag-editor .chips:empty { display: none; }
.form .tag-editor textarea { border: 0; background: transparent; padding: 0.625rem 0.25rem; }
.form .tag-editor textarea:focus-visible { outline: none; }
.tag-chip { cursor: pointer; font: inherit; text-align: left; }
.tag-chip > span:last-child { color: var(--muted); margin-left: 0.25rem; font-size: 1.25rem; }
.tag-chip:hover { border-color: var(--accent); }
.tag-suggestions { max-height: 15rem; overflow-y: auto; border-top: 1px solid var(--border); padding-top: 0.375rem; }
.tag-option { display: flex; align-items: center; gap: 0.5rem; width: 100%; min-height: 44px; padding: 0.5rem 0.75rem; border: 0; border-radius: 8px; background: var(--bg); color: var(--fg); font: inherit; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
.tag-option:hover, .tag-option[aria-selected="true"] { background: var(--surface); outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-picker { flex-basis: 100%; display: grid; gap: 0.5rem; min-width: 0; }
.icon-options { display: grid; width: 100%; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 0.375rem; max-height: 15rem; overflow-y: auto; padding: 0.25rem; }
.icon-option { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0.25rem; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 1.5rem; cursor: pointer; }
.icon-option:hover, .icon-option[aria-pressed="true"] { border-color: var(--accent); background: var(--surface); }
.icon-option[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-picker > .link-button { justify-self: start; min-height: 44px; }

.day-heading { overflow-wrap: anywhere; margin: 0; font-size: 1.375rem; }
a.btn { text-decoration: none; }
.day-comment { white-space: pre-wrap; overflow-wrap: anywhere; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.day-background { display: block; width: 100%; max-height: 16rem; object-fit: cover; border-radius: 8px; margin-bottom: 1rem; }
.day-attachments progress { display: block; width: 100%; height: 0.75rem; margin: -0.5rem 0 0.75rem; accent-color: var(--accent); }
.attachment-list { list-style: none; display: grid; gap: 0.75rem; margin: 1rem 0; padding: 0; }
.attachment-item { min-width: 0; display: grid; gap: 0.5rem; }
.attachment-row { display: flex; align-items: center; gap: 0.375rem; min-width: 0; flex-wrap: wrap; }
.attachment-name { min-width: 0; flex: 1 1 0; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-row > .hint { margin-left: auto; white-space: nowrap; font-size: 0.75rem; }
.attachment-action { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; min-height: 2.75rem; padding: 0; }
.attachment-edit > summary { list-style: none; cursor: pointer; }
.attachment-edit > summary::-webkit-details-marker { display: none; }
.attachment-edit[open] { display: contents; }
.attachment-rename { flex-basis: 100%; order: 1; min-width: 0; }
.attachment-rename input { width: 100%; min-width: 0; }
.attachment-add > summary { display: inline-flex; cursor: pointer; list-style: none; }
.attachment-add > summary::-webkit-details-marker { display: none; }
.attachment-upload .media-panel-head { display: none; }
.attachment-preview { min-width: 0; display: grid; gap: 0.5rem; overflow-wrap: anywhere; }
.attachment-preview img { display: block; max-height: 18rem; object-fit: contain; border-radius: 6px; }
.attachment-preview audio, .attachment-preview video { width: 100%; }
.attachment-player { display: grid; gap: 0.5rem; min-width: 0; }
.attachment-player[hidden] { display: none; }
.attachment-player audio { display: block; width: 100%; min-width: 0; }
.attachment-player .alert { margin: 0; }
.voice-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.voice-controls[hidden] { display: none; }
.voice-feedback { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.5rem 0.75rem; width: 100%; }
.voice-feedback > span, .voice-feedback > .voice-level { grid-column: 1; min-width: 0; }
.voice-timer { font-variant-numeric: tabular-nums; }
.voice-level { display: flex; align-items: center; gap: 0.5rem; }
.voice-level meter { width: 8rem; height: 1.25rem; }
.record-actions { display: flex; gap: 0.5rem; grid-column: 2; grid-row: 1 / 3; }
.record-icon { width: 44px; min-height: 44px; padding: 0.5rem; }
.record-icon[hidden] { display: none; }
.upload-file-list { list-style: none; display: grid; gap: 0.5rem; margin: 0.75rem 0 0; padding: 0; }
.upload-file-list:empty { display: none; }
.upload-file-list li { display: flex; align-items: center; gap: 0.75rem; min-width: 0; overflow-wrap: anywhere; }
.upload-file-list img, .upload-file-icon { flex: none; width: 48px; height: 56px; object-fit: contain; border-radius: 4px; }
.upload-field { position: relative; display: grid; gap: 0.5rem; min-width: 0; }
.upload-dropzone { display: grid; justify-items: center; align-content: center; gap: 0.75rem; min-height: 12rem; padding: 1.5rem 1rem; border: 1px dashed var(--control-border); border-radius: 8px; background: var(--bg); text-align: center; cursor: pointer; font-size: 0.875rem; }
.upload-field:focus-within .upload-dropzone, .upload-dropzone:hover, .upload-dropzone.is-dragging { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.upload-field:focus-within .upload-dropzone { outline: 2px solid var(--focus); outline-offset: 2px; }
.upload-field > input.visually-hidden:focus-visible { outline: none; }
.upload-choose { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.upload-document { width: 56px; height: 56px; }
.upload-document-sheet { fill: var(--border); }
.upload-document-fold { fill: var(--control-border); }
.upload-document-badge { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.upload-document-arrow { fill: none; stroke: var(--on-accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.file-type-icon { display: block; overflow: visible; }
.file-type-sheet { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; stroke-linejoin: round; }
.file-type-fold { fill: var(--border); }
.file-type-label { fill: var(--file-type-color, var(--accent)); }
.file-type-extension { fill: #fff; font: 700 7px system-ui, sans-serif; letter-spacing: 0.15px; }
.file-type-glyph { fill: none; stroke: var(--file-type-color, var(--accent)); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.file-type-glyph circle, .file-type-glyph rect { fill: var(--surface); }
.file-type-glyph path + path { fill: none; }
.file-type-icon[data-category="pdf"] { --file-type-color: #c83b36; }
.file-type-icon[data-category="text"], .file-type-icon[data-category="word"] { --file-type-color: #3482c5; }
.file-type-icon[data-category="sheet"] { --file-type-color: #4b9b62; }
.file-type-icon[data-category="image"], .file-type-icon[data-category="design"] { --file-type-color: #d0a83b; }
.file-type-icon[data-category="audio"] { --file-type-color: #7950c2; }
.file-type-icon[data-category="video"] { --file-type-color: #cd635e; }
.file-type-icon[data-category="archive"] { --file-type-color: #4297ae; }
.file-type-icon[data-category="code"] { --file-type-color: #2d9ba4; }
.file-type-icon[data-category="slides"] { --file-type-color: #d77d45; }
.file-type-icon[data-category="app"] { --file-type-color: #747d8c; }
.upload-file-list li { padding: 0.5rem; background: var(--bg); border-radius: 8px; }
.upload-file-name { flex: 1; min-width: 0; }
.upload-remove { border: 0; background: transparent; }
.media-add { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0.5rem; flex-shrink: 0; }
.upload-dialog { padding: 0; width: min(32rem, calc(100vw - 2rem)); }
.upload-dialog .media-upload-panel { border: 0; margin: 0; }
.media-upload-panel h2 { font-size: 1.125rem; margin: 0; }
.media-upload-panel .media-panel-head { display: flex; }
.media-upload-actions { display: flex; gap: 0.5rem; }
.audio-player { display: grid; gap: 0.5rem; width: 100%; min-width: 0; margin: 0; padding: 0.625rem; border: 1px solid var(--border); border-radius: 0.75rem; }
.audio-player[hidden] { display: none; }
.audio-player figcaption { overflow-wrap: anywhere; font-size: 0.875rem; }
.audio-player audio { width: 100%; min-width: 0; }
.audio-player .alert { margin: 0; }
.attachment-upload { margin-top: 1rem; }
.upload-progress { display: block; width: 100%; min-width: 0; height: 1rem; accent-color: var(--accent); }
.upload-status { margin: 0; overflow-wrap: anywhere; }
.day-attachments .upload-progress { margin: 0; }

/* Day visual states (SPEC §3.5). --state colors the default accent; a custom
   style color is an SVG fill attribute, which wins over the :not([fill]) rule. */
.day-future, .day-today { --state: #dd6b20; --state-text: #975a16; }
.day-past { --state: #3182ce; --state-text: #2b6cb0; }
.day-archived { --state: #a0aec0; --state-text: var(--muted); }
.day-shared { border-style: dashed; }
.day-accent { position: absolute; display: block; pointer-events: none; }
.day-accent rect:not([fill]) { fill: var(--state); }

:root[data-theme="dark"] .day-future, :root[data-theme="dark"] .day-today { --state: #f6ad55; --state-text: #f6ad55; }
:root[data-theme="dark"] .day-past { --state: #63b3ed; --state-text: #90cdf4; }
:root[data-theme="dark"] .day-archived { --state: #4a5568; }

.badge-archived, .badge-shared { color: var(--fg); background: var(--bg); white-space: nowrap; }

.home-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.home-head .tagline { margin: 0; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.segmented a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  font-weight: 500;
}
.segmented a[aria-current="page"] { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.segmented a:not([aria-current]):hover { background: var(--bg); }

.day-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.empty-list { margin: 0; padding: 2rem var(--space); text-align: center; color: var(--muted); }

.day-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
  padding: 0.75rem 0.875rem 0.75rem 1.125rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
}
.day-item:hover, .day-item:focus-visible { border-color: var(--state); }
.day-item .day-accent { left: 0; top: 0; bottom: 0; width: 6px; height: 100%; }
.day-item-icon { flex: none; width: 2rem; font-size: 1.5rem; text-align: center; }
.day-item-main { flex: 1; min-width: 0; display: grid; gap: 0.125rem; }
.day-item-title { font-weight: 600; overflow-wrap: anywhere; }
.day-item-date { color: var(--muted); font-size: 0.875rem; }
.day-item-label { flex: none; max-width: 40%; text-align: right; font-weight: 700; color: var(--state-text); }
.day-archived .day-item-title, .day-archived .day-item-label { color: var(--muted); }
.shared-list-item { display: flex; align-items: center; gap: 0.5rem; }
.shared-list-item .day-item { flex: 1; min-width: 0; }
.shared-hide-form { flex: none; padding-right: 0.5rem; }
.chips-small { gap: 0.25rem; margin-top: 0.25rem; }
.chip.chip-small { min-height: 0; padding: 0 0.5rem; font-size: 0.75rem; }
.chip-small .swatch { width: 0.75rem; height: 0.75rem; }

.day-card { position: relative; width: 100%; max-width: 32rem; aspect-ratio: 1; justify-self: center; min-width: 0; display: flex; flex-direction: column; gap: 0.875rem; padding-top: calc(var(--space) + 8px); }
.day-card > * { margin: 0; }
.day-card .day-accent { left: 0; top: 0; width: 100%; height: 8px; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.day-card-head { display: flex; justify-content: center; align-items: center; gap: 0.625rem; min-width: 0; }
.day-card-icon { flex: none; font-size: 1.75rem; line-height: 1; }
.day-state, .day-next { text-align: center; }
.day-card.day-archived .day-card-icon, .day-card.day-archived .day-countdown { opacity: 0.7; }
.day-calendar-date { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0.25rem 0.75rem; font-size: clamp(1.75rem, 7vw, 3.5rem); font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; }
.day-calendar-time { font-size: 1.125rem; color: var(--muted); font-weight: 500; }
.day-countdown { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0.5rem; color: var(--state-text); }
.day-display-toggle { display: inline-flex; align-items: center; justify-content: center; align-self: center; min-width: 44px; min-height: 44px; margin: -0.5rem 0; color: var(--muted); }
.day-display-toggle:hover, .day-display-toggle:focus-visible { color: var(--state-text); }
.day-display-toggle .icon { width: 20px; height: 20px; }
.countdown-caption { margin: 0; font-size: 1.125rem; font-weight: 600; }
.day-clock { font-variant-numeric: tabular-nums; font-weight: 700; }
.day-card > .day-meta { margin-top: auto; }
.day-meta { display: flex; align-items: center; gap: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.day-meta-groups { display: flex; flex: 1; min-width: 0; flex-wrap: wrap; align-items: center; gap: 0.375rem 0.625rem; }
.day-repeat { font-size: 0.875rem; color: var(--muted); }
.day-actions { margin-left: auto; align-self: flex-start; }
.day-actions .dropdown-panel a, .day-actions .dropdown-panel button { text-decoration: none; color: var(--fg); }
.day-actions .dropdown-panel .danger-text { color: #c53030; }
:root[data-theme="dark"] .day-actions .dropdown-panel .danger-text { color: #fca5a5; }
.breakdown { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.375rem; margin: 0; padding: 0; list-style: none; }
.breakdown li { padding: 0.25rem 0.625rem; border-radius: 8px; background: var(--bg); }
.breakdown-small li { font-size: 0.875rem; }
.day-ordinal { text-align: center; font-weight: 600; }
.day-since { display: grid; gap: 0.375rem; justify-items: center; text-align: center; }
.day-attachments, .day-card-attachments { border-top: 1px solid var(--border); padding-top: 0.5rem; min-width: 0; }
.day-card-attachments .attachment-list { margin: 0.5rem 0 0; }
.day-section-toggle { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; min-height: 44px; cursor: pointer; list-style: none; font-weight: 600; }
.day-section-toggle::-webkit-details-marker { display: none; }
.expand-icon { transition: transform 0.15s; }
details[open] > .day-section-toggle .expand-icon { transform: rotate(180deg); }
.day-attachments-body { display: grid; gap: 0.75rem; padding-top: 0.75rem; min-width: 0; clear: both; }
.day-attachments-body > * { margin: 0; }
.day-sharing > .form { padding-top: 0.75rem; }
.day-menu-section { display: none; }
.day-menu-section:target { display: block; position: fixed; inset: 0; margin: auto; width: min(36rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); height: fit-content; overflow-y: auto; z-index: 20; box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.5); }
.day-action-dialog { padding: 0; }
.day-action-dialog .day-menu-section { display: block; position: static; width: auto; max-height: none; box-shadow: none; }
.day-dialog-close { float: right; margin-left: 1rem; }
.day-section-heading { margin: 0; font-size: 1.125rem; }
.share-entry { padding-top: 0.75rem; border-top: 1px solid var(--border); }

.form label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  min-height: 44px;
}

.form .check input { width: 1.25rem; height: 1.25rem; margin: 0; }

.hint { margin: 0; color: var(--muted); font-size: 0.875rem; }

.stack { display: grid; gap: var(--space); }
.stack > * { margin: 0; }
.stack h1 { font-size: 1.375rem; }
.form h2 { margin: 0; font-size: 1.125rem; }

.group-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.groups-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.groups-toolbar h1 { margin: 0; }
.groups-toolbar .icon-button { font-size: 1.75rem; }
.group-summary { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.tag-list li { max-width: 100%; min-width: 0; }
.tag-list .tag-item { border-radius: 8px 999px 999px 8px; flex-wrap: wrap; padding-left: 1rem; }
.tag-item::before { content: ""; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--muted); flex: none; }
.tag-item .group-summary { flex-wrap: wrap; }
.collection-list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); gap: 1.25rem; }
.collection-list .collection-card { position: relative; isolation: isolate; display: flex; flex-direction: column; align-items: stretch; gap: 0.75rem; min-height: 12rem; height: 100%; overflow: hidden; padding: 1.25rem 1rem 1rem 2rem; border-radius: 4px 14px 14px 4px; box-shadow: 2px 3px 0 var(--border); }
.collection-cover { position: absolute; inset: 0; width: 100%; height: 100%; fill: var(--accent); opacity: 0.18; z-index: -1; }
.notebook-spine { position: absolute; inset: 0 auto 0 0; width: 0.75rem; border-right: 1px solid var(--control-border); background: var(--surface); opacity: 0.65; }
.collection-card .group-summary { flex-wrap: wrap; font-weight: 600; }
.collection-card .group-count { margin-top: auto; }
.collection-comment { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.collection-description { overflow-wrap: anywhere; white-space: pre-wrap; }

.group-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
}

.group-item:hover, .group-item:focus-visible { border-color: var(--accent); }

.group-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.group-count { color: var(--muted); font-size: 0.875rem; white-space: nowrap; }

.group-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; overflow-wrap: anywhere; }
.group-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.group-toolbar .group-heading { margin: 0; min-width: 0; }
.group-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.group-actions .danger-text { color: #c53030; }
.archive-toggle[aria-pressed="true"] { color: var(--on-accent); background: var(--accent); }

.swatch { width: 1rem; height: 1rem; flex: none; }
.group-heading .swatch { width: 1.25rem; height: 1.25rem; }
.swatch-none { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 2 2; }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.color-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem; }
.form .color-label { display: flex; align-items: center; gap: 0.5rem; }
.form input[type="color"] {
  width: 3rem;
  height: 44px;
  padding: 0.125rem;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--bg);
}

.color-palette, .color-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; }
.color-palette { min-width: 0; }
.color-presets { display: contents; }
.color-option { display: grid; place-items: center; width: 44px; height: 44px; flex: none; padding: 3px; border: 1px solid var(--control-border); border-radius: 50%; background: var(--bg); cursor: pointer; }
.color-option svg { width: 100%; height: 100%; }
.color-option:hover, .color-option[aria-pressed="true"], .color-picker-enhanced .color-label.is-selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-picker-enhanced .color-label { position: relative; width: 44px; height: 44px; flex: none; overflow: hidden; border: 1px solid var(--control-border); border-radius: 50%; background: conic-gradient(#ef4444, #f59e0b, #eab308, #22c55e, #06b6d4, #3b82f6, #a855f7, #ec4899, #ef4444); cursor: pointer; }
.color-picker-enhanced .color-label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.form .color-picker-enhanced input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.btn-danger { background: #c53030; color: #fff; }
.danger-zone { border-color: #f5c2c2; }

:root[data-theme="dark"] .danger-zone { border-color: #5c2525; }

.alert, .notice {
  margin: 0 0 1rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
}

.alert { background: #fde8e8; color: #9b1c1c; }

.notice { background: #e6f4ea; color: #1e4620; }

:root[data-theme="dark"] .alert { background: #3b1717; color: #fca5a5; }
:root[data-theme="dark"] .notice { background: #16301f; color: #9ae6b4; }

@media (min-width: 768px) {
  :root { --space: 1.5rem; }
  /* Only sticky when the nav fits on one or two rows; on phones it would cover much of the screen. */
  html { scroll-padding-top: 6rem; }
  .site-header { position: sticky; top: 0; z-index: 5; }
  .brand { font-size: 1.25rem; }
  .field-row { grid-template-columns: 1fr 1fr; }
}

/* Media library and new-day media picker */
.media-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem; }
.media-filters label { display: grid; gap: 0.25rem; flex: 1 1 9rem; min-width: 0; }
.media-filters select { width: 100%; min-width: 0; }
.media-timeline { display: grid; gap: 1.5rem; }
.media-timeline-group { min-width: 0; padding-left: 1rem; border-left: 2px solid var(--border); }
.media-timeline-group h2 { margin: 0 0 0.75rem; font-size: 1.125rem; }
.media-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr)); }
.media-card { display: grid; grid-template-rows: auto 1fr; gap: 0.5rem; padding: 0.5rem; min-width: 0; }
.media-card-preview { display: grid; place-items: center; gap: 0.5rem; min-height: 8rem; border-radius: 8px; background: var(--bg); overflow: hidden; }
.media-card-preview img, .media-card-preview video { display: block; width: 100%; max-height: 14rem; object-fit: cover; }
.media-card-preview a { display: block; width: 100%; }
.media-card-preview audio { width: calc(100% - 1rem); }
.media-card-body { display: grid; align-content: start; gap: 0.125rem; min-width: 0; overflow-wrap: anywhere; }
.media-card-name { font-weight: 500; }
.media-card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-detail { display: grid; gap: 1.5rem; min-width: 0; }
.media-detail-preview { display: grid; place-items: center; min-width: 0; }
.media-detail-preview img, .media-detail-preview video { max-width: 100%; max-height: 75vh; object-fit: contain; }
.media-detail-preview audio { width: 100%; }
.media-detail .media-card-body { gap: 0.75rem; }
.media-detail h2 { margin: 0; font-size: 1.125rem; }
.voice-controls audio { display: block; width: 100%; margin-top: 0.75rem; }
.voice-controls audio[hidden] { display: none; }
@media (min-width: 48rem) {
  .media-detail { grid-template-columns: minmax(0, 1fr) minmax(14rem, 20rem); }
}
.media-card-body .inline-form { justify-self: start; }
.media-thumb-icon { display: grid; place-items: center; }
.media-file-type-icon { width: 64px; height: 72px; }
.empty-state { text-align: center; }

.media-picker-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; flex-basis: 100%; }
.media-picker-bar .btn { display: inline-flex; align-items: center; gap: 0.5rem; }
.media-panel { flex-basis: 100%; display: grid; gap: 0.75rem; min-width: 0; }
.media-panel-head { display: none; align-items: center; justify-content: space-between; gap: 0.75rem; }
.media-panel-head h2 { margin: 0; font-size: 1.125rem; }
.media-panel-fallback-heading { margin: 0 0 0.5rem; font-size: 1rem; }
.media-panel .tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.media-panel .tab { min-width: 0; padding: 0.5rem 0.375rem; font-size: 0.875rem; white-space: normal; overflow-wrap: anywhere; }
.media-picker-enhanced .media-panel-head { display: flex; }
.media-picker-enhanced .media-panel-fallback-heading { display: none; }
.media-dialog { width: min(48rem, calc(100vw - 2rem)); }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { min-height: 44px; padding: 0.5rem 1rem; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: grid; gap: 0.75rem; min-width: 0; }
.media-pick-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); max-height: 55vh; overflow-y: auto; }
.form label.media-pick { position: relative; display: grid; gap: 0.25rem; padding: 0.375rem; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; font-weight: 400; min-width: 0; }
.media-pick:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.media-pick:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.media-pick input { position: absolute; top: 0.5rem; left: 0.5rem; width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--accent); }
.media-pick-thumb { display: grid; place-items: center; aspect-ratio: 1; border-radius: 6px; background: var(--bg); overflow: hidden; }
.media-pick-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-pick-name, .media-pick-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; }
