/* ==================== Variables ==================== */
:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #484f58;
  --border: #30363d;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --error: #f85149;
  --code-bg: #1c2128;
  --link: #58a6ff;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-card: #f6f8fa;
  --text: #1f2328;
  --text-dim: #656d76;
  --text-muted: #8b949e;
  --border: #d0d7de;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --code-bg: #f6f8fa;
  --link: #0969da;
}

/* ==================== Reset ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  min-height: 100vh;
}

/* ==================== State views ==================== */
.state-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  color: var(--text-dim);
}

/* Spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Password card */
.password-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 360px;
  width: 100%;
}
.password-card svg {
  color: var(--text-muted);
  margin-bottom: 16px;
}
.password-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}
.password-card form {
  display: flex;
  gap: 8px;
}
.password-card input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.password-card input:focus {
  border-color: var(--accent);
}
.password-card button {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.password-card button:hover {
  background: var(--accent-hover);
}
.error-text {
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
}

/* Error card */
.error-card {
  text-align: center;
}
.error-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.error-card p {
  color: var(--text-dim);
  font-size: 15px;
}

/* ==================== Note view ==================== */
article header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

#note-title {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
  color: var(--text);
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
}

.category-badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.category-badge:empty { display: none; }

.source-url {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--link);
  text-decoration: none;
  word-break: break-all;
}
.source-url:hover { text-decoration: underline; }

/* ==================== Status chips ==================== */
.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

/* Protected chip - amber */
.chip-protected {
  background: rgba(217, 119, 6, 0.12);
  color: #d97706;
}
[data-theme="light"] .chip-protected {
  background: rgba(217, 119, 6, 0.1);
  color: #b45309;
}

/* Expires chip - indigo (default) */
.chip-expires {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
}

/* Expires chip - warning (< 24h) */
.chip-expires.chip-warning {
  background: rgba(217, 119, 6, 0.12);
  color: #d97706;
}
[data-theme="light"] .chip-expires.chip-warning {
  color: #b45309;
}

/* Expires chip - critical (< 1h) */
.chip-expires.chip-critical {
  background: rgba(248, 81, 73, 0.12);
  color: var(--error);
  animation: chip-pulse 2s ease-in-out infinite;
}
@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Views chip - muted gray */
.chip-views {
  background: rgba(139, 148, 158, 0.1);
  color: var(--text-dim);
}

/* Live chip - green */
.chip-live {
  background: rgba(63, 185, 80, 0.12);
  color: #3fb950;
}
[data-theme="light"] .chip-live {
  color: #1a7f37;
  background: rgba(26, 127, 55, 0.1);
}

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: live-pulse 1.5s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ==================== Countdown bar ==================== */
.countdown-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 24px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--accent);
}
.countdown-bar.warning {
  background: rgba(217, 119, 6, 0.1);
  border-color: rgba(217, 119, 6, 0.25);
  color: #d97706;
}
[data-theme="light"] .countdown-bar.warning {
  color: #b45309;
}
.countdown-bar.critical {
  background: rgba(248, 81, 73, 0.1);
  border-color: rgba(248, 81, 73, 0.25);
  color: var(--error);
  animation: countdown-pulse 2s ease-in-out infinite;
}
@keyframes countdown-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ==================== Note body (markdown) ==================== */
.note-body {
  font-size: 16px;
  line-height: 1.8;
}

.note-body h1, .note-body h2, .note-body h3,
.note-body h4, .note-body h5, .note-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.note-body h1 { font-size: 1.6em; }
.note-body h2 { font-size: 1.4em; }
.note-body h3 { font-size: 1.2em; }

.note-body p {
  margin-bottom: 1em;
}

.note-body a {
  color: var(--link);
  text-decoration: none;
}
.note-body a:hover { text-decoration: underline; }

.note-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1em 0;
}

.note-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 16px;
  margin: 1em 0;
  color: var(--text-dim);
  background: var(--bg-card);
  border-radius: 0 8px 8px 0;
}

.note-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 1em 0;
  font-size: 14px;
  line-height: 1.5;
}
.note-body code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9em;
}
.note-body :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}

.note-body ul, .note-body ol {
  margin: 0.5em 0 1em 1.5em;
}
.note-body li {
  margin-bottom: 0.3em;
}

.note-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.note-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}
.note-body th, .note-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.note-body th {
  background: var(--bg-card);
  font-weight: 600;
}

/* ==================== Footer ==================== */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.footer-content {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-dim);
}
.footer-content strong {
  color: var(--text);
}
.cta-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.cta-link:hover { text-decoration: underline; }

.theme-btn {
  position: fixed;
  bottom: 10px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.15s, border-color 0.15s;
}
.theme-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ==================== Responsive ==================== */
@media (max-width: 600px) {
  #app {
    padding: 20px 16px 80px;
  }
  #note-title {
    font-size: 22px;
  }
  .note-body {
    font-size: 15px;
  }
}
