:root {
  --bg: #0b0d12;
  --surface: #131722;
  --surface-2: #1b2030;
  --border: #272e42;
  --text: #f3f5fa;
  --muted: #98a2b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-fg: #06131c;
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #dde3ee;
  --text: #111827;
  --muted: #5b657a;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

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

.brand-group {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.live-badge.connected {
  color: var(--success);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.storage-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 170px;
}

.storage-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.storage-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.storage-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Container */
.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 18px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.08s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

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

.btn-danger-text {
  color: var(--danger);
}

.btn-danger-text:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.btn-icon {
  padding: 8px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-full {
  width: 100%;
}

/* Composer */
.composer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.text-input {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  max-height: 320px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hint-desktop {
  font-size: 0.8rem;
  margin-left: 4px;
}

/* Active uploads */
.uploads-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.upload-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
}

.upload-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.upload-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.upload-progress {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.12s linear;
}

/* Feed & Cards */
.items-feed {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.item-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.kind-pill {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
  flex-shrink: 0;
}

.item-title-group {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.item-name {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-sub {
  font-size: 0.77rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.item-body {
  padding: 14px;
}

/* Text / Code previews */
.text-preview {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-sans);
  font-size: 0.94rem;
  max-height: 280px;
  overflow: hidden;
}

.text-preview.expanded {
  max-height: none;
}

.text-preview a {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

.code-preview {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}

.show-more-btn {
  margin-top: 8px;
}

/* Media previews */
.media-preview-wrap {
  display: flex;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 10px;
  overflow: hidden;
}

.image-preview {
  display: block;
  max-width: 100%;
  max-height: 440px;
  object-fit: contain;
  cursor: zoom-in;
}

.video-preview {
  display: block;
  width: 100%;
  max-height: 480px;
  background: #000;
}

.audio-preview {
  width: 100%;
}

.file-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.file-banner-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ext-badge {
  min-width: 48px;
  height: 42px;
  padding: 0 8px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.empty-state p {
  margin: 0 auto;
  max-width: 440px;
  font-size: 0.9rem;
}

/* Drag overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(6, 12, 24, 0.76);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.drop-overlay-card {
  border: 2px dashed var(--accent);
  border-radius: 20px;
  padding: 40px 48px;
  background: var(--surface);
  text-align: center;
  color: var(--text);
}

.drop-overlay-card svg {
  width: 44px;
  height: 44px;
  color: var(--accent);
  margin-bottom: 10px;
}

.drop-overlay-card p {
  margin: 0;
  font-weight: 600;
  font-size: 1.05rem;
}

/* Auth gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.auth-card p {
  margin: 0;
  font-size: 0.9rem;
}

.auth-card input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.auth-card input:focus {
  border-color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1040px, 100%);
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-title-wrap {
  min-width: 0;
}

.modal-title {
  margin: 0;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-subtitle {
  font-size: 0.78rem;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.modal-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.modal-image {
  max-width: 100%;
  max-height: 76vh;
  object-fit: contain;
}

.modal-video {
  width: 100%;
  max-height: 76vh;
  background: #000;
}

.modal-pdf {
  width: 100%;
  height: 76vh;
  border: none;
  border-radius: 8px;
  background: #fff;
}

.modal-code {
  width: 100%;
  max-height: 76vh;
  margin: 0;
  padding: 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.16s ease-out;
}

.toast.error {
  border-color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .hint-desktop {
    display: none;
  }

  .topbar-inner {
    align-items: flex-start;
  }

  .brand-group {
    gap: 8px;
  }

  .storage-wrap {
    width: 100%;
  }

  .item-header {
    padding: 10px 12px;
  }

  .item-body {
    padding: 12px;
  }
}
