/* Feed Tool — styles. Light and dark follow the system setting. */

:root {
  --bg: #f4f1ec;
  --surface: #fffdfa;
  --surface-2: #f8f5f0;
  --border: #e2dcd2;
  --border-strong: #cfc6b8;
  --text: #24211d;
  --muted: #6f675d;
  --accent: #d9480f;
  --accent-strong: #b53b0b;
  --accent-soft: #fde8dc;
  --on-accent: #fff;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --ok: #2f9e44;
  --warn: #e8a33d;
  --code-bg: #2a2622;
  --code-text: #efe8de;
  --code-comment: #9c9284;
  --shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 2px 8px rgba(40, 30, 20, 0.05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #211e1b;
    --surface-2: #1b1917;
    --border: #36312c;
    --border-strong: #4a443d;
    --text: #ece6dd;
    --muted: #a49b8f;
    --accent: #ff7a3d;
    --accent-strong: #ff9461;
    --accent-soft: #3a2418;
    --on-accent: #1a0f08;
    --danger: #ff6b6b;
    --danger-soft: #3a1c1c;
    --code-bg: #121110;
    --code-text: #e6dfd4;
    --code-comment: #8a8175;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--accent); }

svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.spacer { flex: 1; }

/* --- buttons and fields ----------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-small { min-height: 30px; padding: 4px 10px; font-size: 13.5px; }
.btn-small svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-quiet { border-color: transparent; background: transparent; color: var(--danger); }
.btn-danger-quiet:hover { background: var(--danger-soft); border-color: transparent; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn-danger:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-weight: 400; margin-left: 4px; }
.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field-row > .field { min-width: 180px; }
.field-row > .field-tz { flex: 0 0 110px; min-width: 110px; }

input[type="text"], input[type="url"], input[type="password"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* --- header ----------------------------------------------------------------- */

.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; stroke: none; }
.brand-mark path { stroke: #fff; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }

.feed-picker { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 180px; max-width: 360px; }
.feed-picker select { font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.sync-btn { gap: 8px; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.sync-dot[data-state="synced"], .sync-dot[data-state="idle"] { background: var(--ok); }
.sync-dot[data-state="syncing"] { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.sync-dot[data-state="error"] { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* --- layout ----------------------------------------------------------------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.editor { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.channel { display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2, .items-toolbar h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.panel-note { margin: 0; font-size: 13px; color: var(--muted); }

.count {
  display: inline-block; margin-left: 4px; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--muted);
  vertical-align: 1px;
}
.count:empty { display: none; }

.items-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 2px 0; }

.empty { margin: 0; padding: 28px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); }

/* --- items ------------------------------------------------------------------ */

.items { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.item.is-open { border-color: var(--border-strong); }

.item-head { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 4px; }

.item-toggle {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
}
.item-toggle:hover { background: var(--surface-2); }
.item-toggle > svg { color: var(--muted); transition: transform 0.15s; }
.item-toggle[aria-expanded="true"] > svg { transform: rotate(90deg); }

.item-num {
  flex: none; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 700;
}
.item-head-text { display: flex; flex-direction: column; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-title.is-untitled { color: var(--muted); font-style: italic; }
.item-meta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-actions { display: flex; gap: 2px; flex: none; }

.item-body {
  display: flex; flex-direction: column; gap: 12px;
  padding: 6px 16px 16px 16px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.now-btn { min-height: 36px; }

/* --- preview ---------------------------------------------------------------- */

.preview {
  position: sticky; top: 76px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 96px);
  background: var(--code-bg); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.preview-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px 10px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--code-text);
}
.preview-head h2 { font: 600 13.5px/1.3 var(--mono); }
.preview-head .count { background: transparent; border-color: rgba(255, 255, 255, 0.15); color: var(--code-comment); }
.preview-head .btn:not(.btn-primary) { background: transparent; color: var(--code-text); border-color: rgba(255, 255, 255, 0.2); }
.preview-head .btn:not(.btn-primary):hover { background: rgba(255, 255, 255, 0.08); }

.xml {
  margin: 0; padding: 14px 16px; overflow: auto; flex: 1;
  font: 12.5px/1.55 var(--mono); color: var(--code-text);
  white-space: pre; tab-size: 2;
}

/* --- dialogs ---------------------------------------------------------------- */

.dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dialog-wide { width: min(620px, calc(100vw - 24px)); }
.dialog-small { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(20, 15, 10, 0.45); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
#sync-signed-out, #sync-signed-in { display: flex; flex-direction: column; gap: 12px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; }
.dialog-header h2 { font-size: 19px; }
.dialog-small form { padding: 20px; }
.dialog-small h2 { font-size: 18px; margin-bottom: 8px; }
.dialog-small p { margin: 0 0 18px; color: var(--muted); }
.dialog-footer { display: flex; gap: 8px; align-items: center; }

.panel-title { font-size: 15px; margin-bottom: 4px; }
.panel-text { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.panel-warning { margin: 10px 0; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 13.5px; }
.form-error { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13.5px; }

.key-field { display: flex; gap: 6px; margin: 0; }
.key-field input { font-family: var(--mono); font-size: 13px; }
.generated-key { display: flex; flex-direction: column; gap: 8px; }
.signin-options { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.signin-options .or { text-align: center; font-size: 13px; color: var(--muted); }

.button-row { display: flex; gap: 8px; flex-wrap: wrap; }
.button-row-end { justify-content: flex-end; margin-top: 8px; }

.sync-state { display: flex; gap: 10px; align-items: flex-start; }
.sync-state .sync-dot { margin-top: 6px; }
.sync-state-title { font-weight: 700; }
.sync-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 4px 0 12px; font-size: 13.5px; }
.sync-facts dt { color: var(--muted); }
.sync-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.sync-facts code { font-family: var(--mono); font-size: 12.5px; }
.relays summary { cursor: pointer; font-weight: 600; }
.relays[open] summary { margin-bottom: 8px; }
.relays > p:last-child { margin-bottom: 0; }
.relays textarea { font-family: var(--mono); font-size: 13px; }


/* --- toast, drop overlay, footer ------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100vw - 32px); padding: 10px 12px 10px 16px;
  background: var(--text); color: var(--bg); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  font-size: 14px;
}
.toast .btn { background: transparent; color: var(--bg); border-color: currentColor; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(217, 72, 15, 0.12); border: 3px dashed var(--accent);
}
.drop-overlay p { padding: 14px 20px; border-radius: 10px; background: var(--surface); font-weight: 600; box-shadow: var(--shadow); }

.app-footer { padding: 4px 20px 20px; text-align: center; font-size: 12.5px; color: var(--muted); }
.app-footer a { margin-left: 6px; }

/* --- small screens ---------------------------------------------------------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .preview { position: static; max-height: 70vh; }
}

@media (max-width: 640px) {
  .app-header { padding: 10px 16px; gap: 10px; }
  .feed-picker { order: 3; flex-basis: 100%; max-width: none; }
  .btn-label { display: none; }
  .item-body { padding: 12px; }
  .item-actions .icon-btn { width: 30px; }
}
