:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --text: #17202a;
  --muted: #657182;
  --line: rgba(24, 34, 46, 0.1);
  --accent: #1a7f6a;
  --accent-soft: rgba(26, 127, 106, 0.11);
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(17, 27, 39, 0.13);
  --radius: 14px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --panel: rgba(23, 30, 37, 0.86);
    --panel-solid: #171f27;
    --text: #edf1f4;
    --muted: #a2aeb9;
    --line: rgba(237, 241, 244, 0.12);
    --accent: #4cc3a6;
    --accent-soft: rgba(76, 195, 166, 0.14);
    --danger: #ff8a75;
    --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 10%, var(--bg)), var(--bg) 40%);
  color: var(--text);
}

.app-shell {
  width: min(420px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

section {
  min-height: 100vh;
  padding: 30px 22px 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; }
h3 { margin: 0; font-size: 14px; }

.auth-subtitle {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 13px;
}

#auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  border-radius: 11px;
}

#auth-tabs button {
  border: 0;
  padding: 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
}

#auth-tabs button.active { background: var(--panel-solid); color: var(--text); box-shadow: 0 1px 5px rgba(0,0,0,.08); }

form { display: grid; gap: 12px; }

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  padding: 10px;
  border-radius: 9px;
  font: inherit;
}

textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 8px;
  font: inherit;
  font-weight: 650;
}

button[type="submit"], #logout, #refresh-devices { min-height: 38px; }
button[type="submit"] { background: var(--accent); border-color: transparent; color: white; }
button:disabled { opacity: .55; }

#auth-tabs button, .item-actions button, .toolbar button { min-height: 30px; padding: 4px 8px; }

.key-result {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--accent-soft);
}
.key-result p { margin: 0 0 6px; font-size: 11px; font-weight: 750; color: var(--muted); text-transform: uppercase; }
.key-result code { display: block; overflow-wrap: anywhere; font-size: 11px; }
.key-result button { margin-top: 8px; }

.warning { margin: 2px 0 0; color: var(--muted); font-size: 11px; }

.app-header { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.connection { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #a5aeb7; box-shadow: 0 0 0 3px rgba(165,174,183,.16); }
.dot[data-status="online"] { background: #22a06b; box-shadow: 0 0 0 3px rgba(34,160,107,.17); }
.dot[data-status="connecting"] { background: #e0a52e; box-shadow: 0 0 0 3px rgba(224,165,46,.18); }
.dot[data-status="offline"] { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }

.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto auto; gap: 8px; align-items: end; margin: 22px 0 12px; }
.filter-field { min-width: 0; }
.filter-field span { display: block; margin-bottom: 4px; font-size: 10px; color: var(--muted); font-weight: 700; }
.filter-field select { width: 100%; min-height: 30px; }
.search-field { gap: 4px; font-size: 11px; }
.toolbar button { min-width: 38px; }

.status { margin: 0 0 10px; padding: 9px 10px; border-radius: 9px; background: var(--accent-soft); color: var(--text); font-size: 12px; }
.status.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 11%, transparent); font-weight: 650; }
.sync-mode { display: flex; align-items: center; gap: 7px; margin: -2px 0 10px; color: var(--muted); font-size: 12px; font-weight: 650; }
.sync-mode input { accent-color: var(--accent); }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }

#history-list { list-style: none; margin: 0; padding: 0; max-height: min(48vh, 430px); overflow: auto; }
#history-list:empty { display: none; }

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-solid);
}
.item-main { display: flex; gap: 9px; min-width: 0; flex: 1; }
.item-image { width: 58px; height: 46px; flex: 0 0 auto; border-radius: 6px; object-fit: cover; background: color-mix(in srgb, var(--muted) 16%, transparent); }
.row-number { flex: 0 0 18px; color: var(--muted); font-size: 11px; font-weight: 750; text-align: right; padding-top: 2px; }
.item-text { min-width: 0; display: grid; gap: 2px; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 13px; }
.item-preview { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }
.item-rich { margin-top: 3px; max-height: 76px; overflow: hidden; font-size: 12px; line-height: 1.35; color: var(--muted); }
.item-rich p, .item-rich ul, .item-rich ol, .item-rich pre, .item-rich blockquote, .item-rich h1,
.item-rich h2, .item-rich h3, .item-rich h4, .item-rich h5, .item-rich h6 { margin: 0; font-size: inherit; font-weight: inherit; }
.item-rich pre { white-space: pre-wrap; }
.item-meta { color: var(--muted); font-size: 10px; }
.item-actions { display: grid; grid-auto-flow: column; gap: 4px; flex: none; }
.item.favorite { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.item.pinned::before { content: "P"; position: absolute; }
.item.pinned { border-left: 3px solid var(--accent); padding-left: 6px; }
.item.copied { outline: 2px solid var(--accent); outline-offset: 1px; }
.item.saved { outline: 2px solid var(--accent); outline-offset: 1px; }
.type-image .item-title::before { content: "IMG · "; color: var(--muted); font-size: 10px; }
.type-files .item-title::before { content: "FILE · "; color: var(--muted); font-size: 10px; }

.upload-panel { margin-top: 14px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--panel-solid) 72%, transparent); }
.upload-panel form { margin-top: 9px; grid-template-columns: 1fr auto; align-items: end; }
.upload-panel textarea { grid-column: 1 / -1; }
.upload-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.pending-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line));
  border-radius: 9px;
  background: var(--accent-soft);
}
.pending-bar[hidden] { display: none; }
.pending-bar p { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--text); font-size: 12px; font-weight: 650; }
.pending-bar.error {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.pending-bar.error p { color: var(--danger); }
.pending-bar button { flex: none; min-height: 30px; }
.file-button { display: grid; justify-items: center; gap: 0; margin: 0; padding: 8px; border: 1px dashed var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.file-button:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

.sensitive-panel { margin-top: 11px; border-top: 1px solid var(--line); padding-top: 9px; }
.sensitive-panel summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 700; }
.sensitive-panel textarea { width: 100%; margin-top: 9px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.sensitive-toggle { display: flex; align-items: center; gap: 7px; margin-top: 9px; color: var(--text); font-size: 12px; font-weight: 650; }
.sensitive-actions { display: flex; justify-content: end; margin-top: 8px; }
.sensitive-actions button { min-height: 30px; }

.device-panel { margin-top: 14px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--panel-solid) 72%, transparent); }
.device-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.device-header h3 { margin: 0; font-size: 14px; }
.device-summary { margin: 6px 0 8px; color: var(--muted); font-size: 12px; }
.device-summary.error { color: var(--danger); font-weight: 700; }
#device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.device { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-solid); }
.device-main { display: flex; min-width: 0; gap: 8px; }
.device-number { flex: 0 0 14px; color: var(--muted); font-size: 11px; font-weight: 750; }
.device-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.device-meta { display: block; color: var(--muted); font-size: 10px; }
.device button { min-height: 28px; width: 28px; padding: 0; }

.app-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.app-footer div { display: grid; grid-auto-flow: column; gap: 6px; }

@media (max-width: 420px) {
  .app-shell { border-left: 0; border-right: 0; }
  section { padding: 24px 14px 18px; }
  .item-actions { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); width: 64px; }
}
