:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Fira Code", Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #1a2332;
  --muted: #64748b;
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

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

.main {
  flex: 3;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--border);
}

.sidebar-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.75rem;
  overflow-y: auto;
  background: var(--bg);
}

.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}

.history-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.sidebar-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.sidebar-hint {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.btn-icon {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  opacity: 0.7;
}

.btn-icon:hover { opacity: 1; background: var(--bg); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 50vh;
  overflow-y: auto;
}

.history-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  padding: 1rem 0.5rem;
}

.history-item {
  display: block;
  position: relative;
  padding: 0.55rem 1.75rem 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.history-item:hover {
  background: var(--bg);
  border-color: var(--border);
}

.history-item.is-active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.history-item-title {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  word-break: break-word;
}

.history-item-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.history-item-remove {
  position: absolute;
  top: 0.35rem;
  right: 0.25rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.history-item-remove:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.btn-sidebar-toggle {
  display: none;
}

@media (max-width: 900px) {
  .app-body {
    flex-direction: column;
    overflow: auto;
  }

  .main {
    flex: none;
    border-right: none;
    min-height: 60vh;
  }

  .sidebar-column {
    max-width: none;
    flex: none;
    border-top: 1px solid var(--border);
  }

  .history-list {
    max-height: 240px;
  }

  .btn-sidebar-toggle {
    display: inline-block;
  }

  .sidebar-column.is-collapsed {
    display: none;
  }
}

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

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
}

.status.saving { color: var(--accent); }
.status.saved { color: var(--success); }
.status.error { color: var(--danger); }

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s, border-color 0.15s;
}

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

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

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

.btn-ghost { background: transparent; }

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

.toolbar {
  margin-bottom: 0.75rem;
}

.title-input {
  width: 100%;
  font-size: 1.25rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0;
  outline: none;
}

.title-input::placeholder { color: var(--muted); }

.toolbar-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.view-mode .toolbar-options {
  display: none !important;
}

.view-mode .title-input {
  pointer-events: none;
  cursor: default;
}

.view-mode .title-input:disabled,
.view-mode .content-input:disabled {
  opacity: 1;
  cursor: default;
  resize: none;
  -webkit-text-fill-color: var(--text);
}

.view-mode .title-input:disabled::placeholder {
  color: transparent;
}

.chk {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.field-inline input,
.field-inline select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.lock-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1rem;
}

.lock-panel input {
  margin: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.editor-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.editor-wrap:focus-within {
  border-color: var(--accent);
}

.editor-gutter {
  flex-shrink: 0;
  width: 3.25rem;
  padding: 1rem 0.4rem 1rem 0.5rem;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface) 82%, var(--bg));
  border-right: 1px solid var(--border);
  text-align: right;
  user-select: none;
  pointer-events: none;
}

.line-num {
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted);
  opacity: 0.55;
  padding-right: 0.15rem;
}

.line-num.is-active {
  opacity: 0.9;
  color: var(--text);
}

.content-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 300px;
  resize: none;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 1rem;
  outline: none;
}

.content-input:disabled { opacity: 0.6; cursor: not-allowed; }

.footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.footer-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.visit-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  justify-content: center;
  font-size: 0.82rem;
}

.visit-stats strong {
  color: var(--accent);
  font-weight: 700;
}

.link-bar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.875rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.view-mode .link-bar {
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
}

.link-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 1.5rem;
}

.link-bar-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.link-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--muted);
  background: color-mix(in srgb, var(--bg) 70%, var(--surface));
  border: 1px solid var(--border);
  white-space: nowrap;
}

.link-badge.is-public {
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(59, 130, 246, 0.1);
}

.link-badge.is-private {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.35);
  background: rgba(139, 92, 246, 0.1);
}

.link-badge.is-readonly {
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
}

.link-badge.is-locked {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}

.link-url-field {
  display: flex;
  align-items: stretch;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.link-url-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.share-link {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text);
  text-decoration: none;
  word-break: break-all;
  opacity: 0.92;
}

.share-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.btn-copy-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.35rem;
  align-self: stretch;
  padding: 0;
  border: none;
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, var(--bg));
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.btn-copy-icon:hover {
  color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.btn-copy-icon svg {
  display: block;
}

.link-bar-foot {
  padding-top: 0.15rem;
}

.link-bar-foot:not(:has(.link-bar-actions button:not([hidden]))) {
  display: none;
}

.link-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.link-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.link-action-btn:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: rgba(59, 130, 246, 0.06);
}

.link-action-btn svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.view-mode .sidebar-column {
  justify-content: flex-start;
}

.view-mode .banner-below-history {
  margin-top: 0;
  flex: 0 0 auto;
}

.view-mode #banner-ads-sidebar {
  display: block !important;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 1000;
  animation: fadeIn 0.2s;
}

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

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

.not-found-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.not-found-wrap {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.not-found-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.5rem;
}

.not-found-code {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.not-found-card h1 {
  margin: 0.75rem 0 0.5rem;
  font-size: 1.35rem;
}

.not-found-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.not-found-id {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
  font-family: var(--mono);
}

.not-found-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.not-found-brand {
  margin: 1.25rem 0 0;
  font-size: 0.85rem;
}

.not-found-brand a {
  color: var(--muted);
  text-decoration: none;
}

.not-found-brand a:hover {
  color: var(--accent);
}

@media (max-width: 640px) {
  .header { padding: 0.5rem; }
  .main { padding: 0.5rem; }
  .toolbar-options { gap: 0.5rem; }
}
