/* ============================================
   diffmini - Encrypted diff & file sharing
   ============================================ */

/* --- Custom Properties --- */
:root {
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #f0f2f5;
  --fg: #1f2328;
  --fg-muted: #656d76;
  --fg-subtle: #8b949e;
  --border: #d1d9e0;
  --border-light: #e8ecf0;
  --accent: #0969da;
  --danger: #d1242f;
  --success: #1a7f37;
  --diff-add-bg: #dafbe1;
  --diff-add-fg: #116329;
  --diff-del-bg: #ffebe9;
  --diff-del-fg: #82071e;
  --diff-hunk-bg: #ddf4ff;
  --diff-hunk-fg: #0969da;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --fg: #e6edf3;
    --fg-muted: #8b949e;
    --fg-subtle: #6e7681;
    --border: #30363d;
    --border-light: #21262d;
    --accent: #58a6ff;
    --danger: #f85149;
    --success: #3fb950;
    --diff-add-bg: #0d2818;
    --diff-add-fg: #3fb950;
    --diff-del-bg: #2d1117;
    --diff-del-fg: #f85149;
    --diff-hunk-bg: #0d2444;
    --diff-hunk-fg: #58a6ff;
  }
}

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

body, h1, h2, h3, h4, p, ul, ol, figure, blockquote {
  margin: 0;
}

/* --- Base --- */
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Container --- */
.container {
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* --- Typography --- */
h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p {
  color: var(--fg-muted);
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  line-height: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--fg-subtle);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  opacity: 0.9;
  border-color: var(--accent);
}

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 24rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.modal h2 {
  margin-bottom: 0.5rem;
}

.modal p {
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* --- Form --- */
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  line-height: 1.25rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--fg);
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--fg-muted);
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  accent-color: var(--accent);
}

/* --- Error Text --- */
.error-text {
  color: var(--danger);
  font-size: 0.8125rem;
  margin-top: 0.375rem;
}

/* --- Spinner --- */
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Badges --- */
.badge-add {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--diff-add-bg);
  color: var(--diff-add-fg);
  border-radius: 999px;
}

.badge-del {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--diff-del-bg);
  color: var(--diff-del-fg);
  border-radius: 999px;
}

/* --- Diff Viewer --- */
.line-num {
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
  user-select: none;
  padding: 0 0.5rem;
  min-width: 3rem;
  vertical-align: top;
}

.diff-file {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.diff-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.4;
  table-layout: fixed;
}

.diff-table td {
  padding: 0 0.75rem;
  white-space: pre-wrap;
  word-break: break-all;
  vertical-align: top;
}

.diff-line-num {
  width: 2.5rem;
  text-align: right;
  padding-right: 0.5rem;
  color: var(--fg-subtle);
  font-size: 0.75rem;
  user-select: none;
  border-right: 1px solid var(--border-light);
}

.diff-line-content {
  padding-left: 0.5rem;
}

.diff-prefix {
  user-select: none;
  display: inline-block;
  width: 1ch;
}

.diff-summary {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.code-content {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  background: var(--bg);
}

.code-content code {
  font-family: inherit;
  background: none;
  padding: 0;
}

.diff-add,
.diff-line-add {
  background: var(--diff-add-bg);
}
.diff-add td.diff-line-content,
.diff-line-add td.diff-line-content {
  color: var(--diff-add-fg);
}

.diff-del,
.diff-line-del {
  background: var(--diff-del-bg);
}
.diff-del td.diff-line-content,
.diff-line-del td.diff-line-content {
  color: var(--diff-del-fg);
}

.diff-line-ctx {
  background: transparent;
}

.diff-hunk-header,
.diff-hunk-sep {
  background: var(--diff-hunk-bg);
  color: var(--diff-hunk-fg);
  font-style: italic;
}

.diff-hunk-sep td {
  padding: 0.25rem 0.75rem;
}

/* --- File Viewer Layout --- */
.file-viewer {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2px);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.file-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 0.875rem;
  font-weight: 600;
}

.file-viewer-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.file-sidebar {
  width: 16rem;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.file-item,
.file-sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  color: var(--fg-muted);
  cursor: pointer;
  border-left: 2px solid transparent;
  border-bottom: 1px solid var(--border-light);
  text-decoration: none;
  transition: background 0.1s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item:hover,
.file-sidebar-item:hover {
  background: var(--bg-tertiary);
  color: var(--fg);
}

.file-item.active,
.file-sidebar-item.active {
  background: var(--bg);
  color: var(--fg);
  border-left-color: var(--accent);
  font-weight: 500;
}

.file-content {
  flex: 1;
  min-width: 0;
  overflow: auto;
}

.file-header-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Tabs --- */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 0 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
  transition: color 0.1s;
}

.tab:hover {
  color: var(--fg);
}

.tab.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

/* --- Accordion (mobile file list) --- */
.accordion-item {
  border-bottom: 1px solid var(--border-light);
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  background: var(--bg-secondary);
  cursor: pointer;
  user-select: none;
}

.accordion-header:hover {
  background: var(--bg-tertiary);
}

.accordion-arrow {
  font-size: 0.75rem;
  color: var(--fg-muted);
  transition: transform 0.15s;
}

.accordion-body {
  border-top: 1px solid var(--border-light);
}

/* --- Markdown Body --- */
.markdown-body {
  padding: 2rem;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--fg);
  word-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.markdown-body h1 { font-size: 1.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.markdown-body h2 { font-size: 1.375rem; border-bottom: 1px solid var(--border); padding-bottom: 0.375rem; }
.markdown-body h3 { font-size: 1.125rem; }
.markdown-body h4 { font-size: 1rem; }

.markdown-body p {
  color: var(--fg);
  margin-bottom: 1rem;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.markdown-body li {
  margin-bottom: 0.25rem;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

.markdown-body pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1rem;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.875rem;
}

.markdown-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.markdown-body blockquote {
  border-left: 3px solid var(--border);
  padding: 0.25rem 1rem;
  margin: 0 0 1rem 0;
  color: var(--fg-muted);
}

.markdown-body a {
  color: var(--accent);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 6px;
}

/* --- 404 Page --- */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}

.not-found h1 {
  font-size: 4rem;
  font-weight: 700;
  color: var(--fg-subtle);
  margin-bottom: 0.5rem;
}

.not-found p {
  font-size: 1.125rem;
}

/* --- Landing Page --- */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-header {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}

.landing-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.landing-logo {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--fg);
  text-decoration: none;
}

.landing-hero {
  padding: 4rem 0;
  text-align: center;
}

.landing-hero h1 {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.75rem;
}

.landing-hero p {
  font-size: 1.125rem;
  max-width: 32rem;
  margin: 0 auto;
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  padding: 2rem 0 3rem;
}

.landing-features .feature-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.feature-card h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.feature-card p {
  font-size: 0.8125rem;
  line-height: 1.5;
}

.landing-code {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  overflow-x: auto;
  margin-bottom: 2rem;
  white-space: pre;
  color: var(--fg);
}

.landing-section {
  padding: 1.5rem 0;
}

.landing-section h2 {
  margin-bottom: 1rem;
}

.landing-footer {
  margin-top: auto;
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  text-align: center;
}

.landing-footer p {
  font-size: 0.8125rem;
  color: var(--fg-subtle);
}

/* --- Utilities --- */
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--fg-muted); }
.text-sm { font-size: 0.875rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }

/* --- Responsive --- */
.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }

  .landing-hero h1 {
    font-size: 1.75rem;
  }

  .landing-features {
    grid-template-columns: 1fr;
  }

  .file-viewer {
    flex-direction: column;
  }

  .file-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    padding: 0;
  }

  .file-sidebar.collapsed .file-item {
    display: none;
  }

  .file-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--fg-muted);
    cursor: pointer;
    background: var(--bg-secondary);
    border: none;
    width: 100%;
    font-family: var(--font-sans);
  }

  .container {
    padding: 0 1rem;
  }
}

@media (min-width: 769px) {
  .file-sidebar-toggle {
    display: none;
  }
}
