/* Clip web client */

:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --surface-3: #e6e9f3;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a8;
  --border: #e1e5ef;
  --primary: #4f46e5;
  --primary-2: #6d28d9;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #131b31;
    --surface-2: #1a2440;
    --surface-3: #222e50;
    --text: #e5e9f2;
    --text-2: #a7b2c8;
    --muted: #6d7a96;
    --border: #253152;
    --primary: #8b93ff;
    --primary-2: #a78bfa;
    --primary-soft: #1f2750;
    --on-primary: #0b1020;
    --danger: #f87171;
    --danger-soft: #3a1c24;
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #131b31;
  --surface-2: #1a2440;
  --surface-3: #222e50;
  --text: #e5e9f2;
  --text-2: #a7b2c8;
  --muted: #6d7a96;
  --border: #253152;
  --primary: #8b93ff;
  --primary-2: #a78bfa;
  --primary-soft: #1f2750;
  --on-primary: #0b1020;
  --danger: #f87171;
  --danger-soft: #3a1c24;
  --success: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

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

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

.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: var(--on-primary); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.small { height: 32px; padding: 0 10px; font-size: 14px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: none; border-radius: 9px; background: transparent; color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.active { color: var(--primary); }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.hint { font-size: 13px; color: var(--muted); }
.error-text { color: var(--danger); font-size: 14px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; cursor: pointer; }
.switch input { appearance: none; flex: none; width: 42px; height: 24px; border-radius: 12px; background: var(--surface-3); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .5; }
.switch .label { display: flex; flex-direction: column; gap: 2px; }

/* ---------- setup screen ---------- */

.setup {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--primary-2) 16%, transparent), transparent 60%),
    var(--bg);
}
.setup-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 28px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand img { width: 44px; height: 44px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin: 6px 0 18px; }
.tabs button { flex: 1; height: 34px; border: none; border-radius: 9px; background: transparent; color: var(--text-2); cursor: pointer; font-size: 14px; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.server-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 16px; }
.server-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--text); font-size: 14px; }

/* encryption key screens */
.setup-card.stack > p { margin: 0; line-height: 1.45; }
.setup-card.stack > .brand { margin-bottom: 6px; }
.code.key-code { font-size: 16px; line-height: 1.5; letter-spacing: .04em; overflow-wrap: anywhere; text-wrap: balance; }
.key-input { font-family: var(--mono); letter-spacing: .04em; }
details.reset { font-size: 14px; }
details.reset summary { cursor: pointer; color: var(--text-2); }
details.reset form { margin-top: 10px; }
details.reset p { margin: 0; }

/* ---------- app shell ---------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 58px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.topbar .logo img { width: 28px; height: 28px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); padding: 4px 10px; border-radius: 20px; background: var(--surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent); }
.dot.connecting { background: var(--warning); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.layout { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .layout { display: flex; flex-direction: column; align-items: stretch; gap: 14px; padding-top: 12px; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-title { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* devices */
.sidebar { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 860px) { .sidebar { position: static; } }
.devices { list-style: none; margin: 0; padding: 4px 8px 10px; }
.device { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; cursor: pointer; }
.device:hover { background: var(--surface-2); }
.device.selected { background: var(--primary-soft); }
.device .dev-icon { position: relative; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.device .dev-icon .dot { position: absolute; right: -2px; bottom: -2px; border: 2px solid var(--surface); width: 11px; height: 11px; box-shadow: none; }
.device .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); vertical-align: 1px; margin-left: 4px; }
@media (max-width: 860px) {
  .devices { display: flex; gap: 6px; overflow-x: auto; padding: 4px 10px 12px; scrollbar-width: none; }
  .device { flex: none; padding: 6px 10px 6px 6px; border: 1px solid var(--border); }
  .device .sub { display: none; }
}
.tip { padding: 14px 16px; font-size: 13.5px; color: var(--text-2); }
@media (max-width: 860px) { .tip { display: none; } }

/* composer */
.composer { padding: 14px; position: relative; }
.composer textarea { width: 100%; min-height: 76px; max-height: 320px; border: none; outline: none; resize: none; background: transparent; padding: 4px 2px; font-size: 15.5px; }
.composer .bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }
.composer select.input { width: auto; max-width: 220px; height: 36px; }
@media (max-width: 560px) {
  .composer .bar .grow { display: none; }
  .composer select.input { flex: 1 1 110px; min-width: 0; max-width: none; }
}
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.attachment { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 4px 4px 10px; border-radius: 9px; background: var(--surface-2); font-size: 13.5px; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.attachment .icon-btn { width: 26px; height: 26px; }
.dropzone { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; border: 2px dashed var(--primary); border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 90%, var(--primary)); color: var(--primary); font-weight: 600; pointer-events: none; }

.transfers { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.transfer { padding: 10px 12px; }
.transfer .row { font-size: 14px; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .2s; }
.update-notes { white-space: pre-line; margin: 2px 0 6px; overflow-wrap: anywhere; }
.transfer.error .progress > div { background: var(--danger); }

/* filters */
.filters { display: flex; gap: 6px; margin: 18px 0 10px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; height: 32px; padding: 0 13px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 14px; }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* feed */
.feed { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; gap: 12px; padding: 14px 14px 12px; animation: appear .25s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(-4px); } }
.item .kind { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--primary-soft); color: var(--primary); }
.item .kind.clip { background: var(--surface-2); color: var(--text-2); }
.item .content { flex: 1; min-width: 0; }
.item .text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.item .text.clamped { display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden; }
.item .link-title { font-weight: 600; overflow-wrap: anywhere; }
.item a.url { overflow-wrap: anywhere; text-decoration: none; }
.item a.url:hover { text-decoration: underline; }
.item .file { display: flex; align-items: center; gap: 12px; }
.item .file .fname { font-weight: 550; overflow-wrap: anywhere; }
.item .thumb.placeholder { width: 200px; height: 120px; cursor: default; animation: pulse 1.4s infinite; }
.item .thumb { display: block; max-width: min(100%, 360px); max-height: 260px; border-radius: 10px; margin-top: 4px; border: 1px solid var(--border); background: var(--surface-2); cursor: zoom-in; object-fit: contain; }
.item .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.item .meta .sep { opacity: .6; }
.item .badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); }
.item .badge svg.icon { width: 12px; height: 12px; }
.item .actions { display: flex; align-items: flex-start; gap: 2px; flex: none; }
.item .more { border: none; background: none; padding: 0; margin-top: 4px; color: var(--primary); cursor: pointer; font-size: 13.5px; }
@media (max-width: 560px) {
  .item { flex-wrap: wrap; }
  .item .actions { width: 100%; justify-content: flex-end; margin-top: -4px; }
}
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg.icon { width: 40px; height: 40px; stroke-width: 1.5; margin-bottom: 10px; }
.feed-footer { display: flex; justify-content: center; padding: 14px 0; }

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

.backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(8, 12, 24, .5); animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.dialog { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 22px; animation: pop .18s ease-out; }
.dialog.wide { max-width: 640px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.dialog h2 { margin: 0 0 14px; font-size: 19px; }
.dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -6px 8px 0; }
.dialog-head h2 { margin: 0; }
.qr { display: block; width: 240px; height: 240px; margin: 8px auto 14px; border-radius: 12px; background: #fff; }
.code { font: 700 30px/1 var(--mono); letter-spacing: .12em; text-align: center; padding: 12px; border-radius: 12px; background: var(--surface-2); user-select: all; }
.preview-img { display: block; max-width: 100%; max-height: 80vh; margin: 0 auto; border-radius: 10px; }

.settings section { padding: 6px 0 14px; border-bottom: 1px solid var(--border); }
.settings section:last-child { border-bottom: none; }
.settings h3 { margin: 12px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.settings .device-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.settings .device-row .name { font-weight: 550; }
.settings .device-row .sub { font-size: 12.5px; color: var(--muted); }
.settings .kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; }
.settings .kv span:last-child { color: var(--text-2); text-align: right; overflow-wrap: anywhere; }
.folder { display: flex; align-items: center; gap: 8px; padding: 6px 0 10px; }
.folder code { flex: 1; min-width: 0; font: 13px var(--mono); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shortcuts h3 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.shortcuts p { margin: 6px 0 10px; line-height: 1.45; }
.shortcuts .recipe { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.shortcuts .recipe summary { cursor: pointer; font-weight: 600; }
.shortcuts .recipe ol { margin: 10px 0 4px; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; line-height: 1.45; }
.copy-row { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.copy-value { display: flex; align-items: center; gap: 8px; }
.copy-value code { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font: 13px var(--mono); overflow-wrap: anywhere; user-select: all; }

/* ---------- toasts ---------- */

.toasts { position: fixed; z-index: 60; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 14px; pointer-events: auto; animation: toast-in .2s ease-out; max-width: 100%; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { border: none; background: none; color: inherit; font-weight: 700; cursor: pointer; padding: 0 0 0 6px; text-decoration: underline; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
