:root {
  color-scheme: light;
  --color-bg: #f4f5fb;
  --color-bg-gradient: radial-gradient(
      1200px 600px at 10% -10%,
      rgba(99, 102, 241, 0.12),
      transparent 60%
    ),
    radial-gradient(
      900px 500px at 110% 10%,
      rgba(244, 63, 94, 0.08),
      transparent 55%
    ),
    linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  --color-surface: #ffffff;
  --color-surface-muted: #f8fafc;
  --color-surface-soft: #f1f5f9;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-text: #0f172a;
  --color-text-soft: #334155;
  --color-text-muted: #64748b;
  --color-text-faint: #94a3b8;
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-primary-soft: #eef2ff;
  --color-accent: #f43f5e;
  --color-accent-hover: #e11d48;
  --color-accent-soft: #fff1f2;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-danger-soft: #fee2e2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px -20px rgba(79, 70, 229, 0.25),
    0 8px 20px -12px rgba(15, 23, 42, 0.1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--color-text);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--color-bg);
  background-image: var(--color-bg-gradient);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.15s var(--ease);
}

a:hover {
  color: var(--color-primary-hover);
}

/* ---------- Header ---------- */

.page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.brand:hover {
  color: var(--color-text);
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #f43f5e 100%);
  color: #ffffff;
  box-shadow: 0 6px 16px -6px rgba(99, 102, 241, 0.5);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.welcome {
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.welcome strong {
  color: var(--color-text);
  font-weight: 600;
}

/* ---------- Layout ---------- */

.page-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: grid;
  gap: 28px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--color-danger-soft);
  color: #991b1b;
  border-radius: var(--radius-md);
  border: 1px solid rgba(239, 68, 68, 0.2);
  font-size: 14px;
}

.alert::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2Zm0 15a1.25 1.25 0 1 1 1.25-1.25A1.25 1.25 0 0 1 12 17Zm1-5a1 1 0 0 1-2 0V7a1 1 0 0 1 2 0Z'/></svg>")
    no-repeat center / contain;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2Zm0 15a1.25 1.25 0 1 1 1.25-1.25A1.25 1.25 0 0 1 12 17Zm1-5a1 1 0 0 1-2 0V7a1 1 0 0 1 2 0Z'/></svg>")
    no-repeat center / contain;
}

/* ---------- Panels & Surfaces ---------- */

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.panel-body {
  padding: 24px;
}

.panel-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.panel-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ---------- Auth pages ---------- */

.auth-wrapper {
  min-height: calc(100vh - 68px);
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  display: grid;
  gap: 22px;
}

.auth-card header {
  display: grid;
  gap: 6px;
  text-align: center;
}

.auth-card h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.auth-card .auth-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 6px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #f43f5e 100%);
  color: #ffffff;
  box-shadow: 0 10px 24px -10px rgba(99, 102, 241, 0.6);
}

.switch-link {
  text-align: center;
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ---------- Compose (tabs) ---------- */

.compose {
  position: relative;
}

.compose > input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
  margin: 0;
}

.compose-header {
  padding: 22px 24px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compose-heading h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.compose-heading p {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

.compose-tabs {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}

.compose-tabs label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  user-select: none;
}

.compose-tabs label:hover {
  color: var(--color-text);
}

.compose > input[type="radio"]:focus-visible ~ .compose-header .compose-tabs label[for="compose-tab-text"],
.compose > input[type="radio"]:focus-visible ~ .compose-header .compose-tabs label[for="compose-tab-voice"] {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

#compose-tab-text:checked ~ .compose-header .compose-tabs label[for="compose-tab-text"],
#compose-tab-voice:checked ~ .compose-header .compose-tabs label[for="compose-tab-voice"] {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.compose-panels {
  padding: 18px 24px 24px;
}

.compose-panel {
  display: none;
}

#compose-tab-text:checked ~ .compose-panels .compose-panel-text,
#compose-tab-voice:checked ~ .compose-panels .compose-panel-voice {
  display: block;
  animation: fade-in 0.22s var(--ease);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  gap: 14px;
}

.form-row {
  display: grid;
  gap: 6px;
}

.form-row > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-soft);
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

input[type="file"] {
  padding: 8px 10px;
  font-size: 13px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.05s var(--ease),
    box-shadow 0.2s var(--ease);
  box-shadow: 0 6px 16px -8px rgba(99, 102, 241, 0.55);
}

button:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-button {
  background: var(--color-surface);
  color: var(--color-text-soft);
  border: 1px solid var(--color-border);
  box-shadow: none;
}

.secondary-button:hover:not(:disabled) {
  background: var(--color-surface-muted);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.danger-button {
  background: var(--color-surface);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  box-shadow: none;
}

.danger-button:hover:not(:disabled) {
  background: var(--color-danger-soft);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.5);
}

.ghost-button {
  background: transparent;
  color: var(--color-text-muted);
  box-shadow: none;
  padding: 8px 10px;
}

.ghost-button:hover:not(:disabled) {
  background: var(--color-surface-soft);
  color: var(--color-text);
}

.btn-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.submit-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--color-text-soft);
  cursor: pointer;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

.muted {
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ---------- Voice recorder ---------- */

.voice-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: linear-gradient(
    180deg,
    rgba(248, 250, 252, 0.8) 0%,
    rgba(241, 245, 249, 0.4) 100%
  );
}

.voice-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.record-button {
  background: var(--color-accent);
  box-shadow: 0 8px 20px -8px rgba(244, 63, 94, 0.55);
}

.record-button:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.record-button .record-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ffffff;
  flex: none;
}

.voice-section[data-recording="true"] .record-button .record-dot {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.voice-status {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-section[data-recording="true"] .voice-status {
  color: var(--color-accent-hover);
  font-weight: 500;
}

.voice-section[data-recording="true"] .voice-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: pulse 1s ease-in-out infinite;
}

.transcript-preview {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--color-text-soft);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.voice-section audio,
.audio-attachment audio {
  width: 100%;
  height: 40px;
  border-radius: var(--radius-md);
}

.file-picker {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.audio-attachment {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--color-primary-soft);
  border: 1px solid rgba(99, 102, 241, 0.18);
  border-radius: var(--radius-md);
}

.audio-attachment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
}

.audio-file-label {
  font-size: 12px;
  color: var(--color-text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Transcription option ---------- */

.transcription-box {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
}

.transcription-hint {
  margin: 0;
  font-size: 12px;
  color: var(--color-text-muted);
  padding-left: 26px;
}

/* ---------- Notes section ---------- */

.notes-section {
  display: grid;
  gap: 16px;
}

.notes-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 4px;
}

.notes-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.notes-count {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.18s var(--ease);
}

.note-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-strong);
}

.note-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.note-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
  word-break: break-word;
}

.note-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(244, 63, 94, 0.2);
  white-space: nowrap;
}

.note-badge svg {
  width: 11px;
  height: 11px;
}

.note-card-preview {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.note-card-preview.empty {
  color: var(--color-text-faint);
  font-style: italic;
}

.note-card-audio {
  padding-top: 4px;
}

.note-card-audio audio {
  width: 100%;
  height: 38px;
}

.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  margin-top: auto;
  border-top: 1px solid var(--color-surface-soft);
  font-size: 12px;
  color: var(--color-text-faint);
}

.note-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.note-card-meta svg {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}

.note-card-actions {
  display: flex;
  gap: 6px;
}

/* Expandable edit details */

.note-edit {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 14px;
}

.note-edit[open] {
  animation: fade-in 0.22s var(--ease);
}

.note-edit summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  list-style: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.note-edit summary:hover {
  background: var(--color-surface-soft);
  color: var(--color-text);
}

.note-edit summary::-webkit-details-marker {
  display: none;
}

.note-edit summary svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s var(--ease);
}

.note-edit[open] summary svg {
  transform: rotate(180deg);
}

.note-edit-body {
  margin-top: 14px;
  display: grid;
  gap: 14px;
}

.note-delete {
  margin: 0;
}

/* ---------- Empty state ---------- */

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.6);
}

.empty-state-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.empty-state h3 {
  margin: 8px 0 0;
  font-size: 16px;
  color: var(--color-text);
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .header-inner {
    padding: 12px 16px;
  }

  .welcome {
    display: none;
  }

  .page-main {
    padding: 20px 16px 48px;
    gap: 20px;
  }

  .compose-header {
    padding: 18px 18px 0;
    flex-direction: column;
    align-items: stretch;
  }

  .compose-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .compose-tabs label {
    flex: 1;
    justify-content: center;
  }

  .compose-panels {
    padding: 14px 18px 20px;
  }

  .panel-body {
    padding: 18px;
  }

  .auth-card {
    padding: 28px 22px;
  }

  .notes-grid {
    grid-template-columns: 1fr;
  }

  .submit-row {
    flex-direction: column-reverse;
  }

  .submit-row button {
    width: 100%;
  }
}
