/* RustDesk Family – prosty, responsywny interfejs. Motyw ciemny domyślnie. */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --surface-3: #282e38;
  --border: #2c323d;
  --text: #e7eaf0;
  --muted: #98a1b0;
  --accent: #3d7eff;
  --accent-hover: #5b92ff;
  --accent-text: #ffffff;
  --danger: #f0524f;
  --success: #2fbf71;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .22);
  --os-windows: #4ea1ff;
  --os-linux: #f5a524;
  --os-macos: #c8ccd4;
  --os-server: #34c77b;
  --os-other: #a78bfa;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #edf0f4;
  --surface-3: #e2e6ec;
  --border: #d8dde5;
  --text: #151a23;
  --muted: #5b6474;
  --accent: #2563eb;
  --accent-hover: #1d4fd0;
  --danger: #d33a37;
  --success: #1e9e5a;
  --shadow: 0 1px 2px rgba(20, 30, 50, .08), 0 6px 18px rgba(20, 30, 50, .08);
  --os-windows: #1f7ae0;
  --os-linux: #c47d00;
  --os-macos: #5b6270;
  --os-server: #169957;
  --os-other: #7c5ce0;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace; }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-xl { width: 48px; height: 48px; }

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

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.btn-icon { width: 40px; padding: 0; }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Pasek górny ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 250px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
}
.menu-panel button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 8px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.menu-panel button:hover, .menu-panel button:focus-visible { background: var(--surface-2); }
.menu-panel form { margin: 0; }

/* ---------- Główna część ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 16px 16px 48px; }

.search { position: relative; display: flex; align-items: center; }
.search > .icon { position: absolute; left: 16px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 52px; padding: 0 48px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 17px;
  box-shadow: var(--shadow);
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.search-clear {
  position: absolute; right: 8px; width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }
.search-hint { min-height: 20px; margin: 6px 4px 0; font-size: 13px; color: var(--muted); }

.chips {
  display: flex; gap: 8px; margin: 10px 0 18px; padding: 2px 2px 6px;
  overflow-x: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.chip {
  display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
  min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .count {
  min-width: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted);
  font-size: 12px; line-height: 20px; text-align: center;
}
.chip[aria-pressed="true"] .count { background: rgba(255, 255, 255, .22); color: var(--accent-text); }

.status { margin: 0 4px 12px; color: var(--muted); font-size: 14px; }
.status:empty { display: none; }

.group-section + .group-section { margin-top: 26px; }
.group-title {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 4px 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

/* ---------- Karta urządzenia ---------- */
.card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.os-badge {
  --os: var(--os-other);
  width: 44px; height: 44px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--os);
  background: color-mix(in srgb, var(--os) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--os) 30%, transparent);
}
.os-badge .icon { width: 24px; height: 24px; }
.os-windows { --os: var(--os-windows); }
.os-linux { --os: var(--os-linux); }
.os-macos { --os: var(--os-macos); }
.os-server { --os: var(--os-server); }
.os-other { --os: var(--os-other); }

.card-title { min-width: 0; flex: 1; }
.card-title h3 { font-size: 18px; overflow-wrap: anywhere; }
.card-title p { margin: 2px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.group-pill {
  flex-shrink: 0; max-width: 40%;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.rd-id {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px 10px; border-radius: 12px;
  background: var(--surface-2);
}
.rd-id .mono { font-size: 22px; font-weight: 700; letter-spacing: .04em; line-height: 1.3; overflow-wrap: anywhere; user-select: all; }
.rd-id small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.rd-id-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Status online z serwera RustDesk (hbbs). */
.presence { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.presence::before { content: ""; box-sizing: border-box; width: 9px; height: 9px; border-radius: 50%; }
.presence.is-online { color: var(--success); }
.presence.is-online::before { background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent); }
.presence.is-offline { color: var(--muted); }
.presence.is-offline::before { border: 2px solid currentColor; }
.presence-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  margin: -8px 4px 16px; font-size: 13px; color: var(--muted);
}
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { opacity: .5; cursor: progress; text-decoration: none; }

.meta { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 14px; }
.meta li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meta li span { overflow-wrap: anywhere; }
.meta .icon { width: 15px; height: 15px; }
.description { margin: 0; color: var(--text); font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 12px; }

/* "Połącz" - główna akcja na całą szerokość, pod nią "Kopiuj ID" i "Edytuj". */
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }
.card-actions .btn-connect { grid-column: 1 / -1; min-height: 46px; font-size: 16px; }

/* ---------- Stany puste ---------- */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 12px 0 6px; font-size: 20px; }
.empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ---------- Okna dialogowe ---------- */
dialog {
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 8, 12, .6); backdrop-filter: blur(2px); }
dialog form, .dialog-body { padding: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { font-size: 20px; }
.dialog-body h3 { font-size: 15px; margin: 18px 0 8px; }
.dialog-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-weight: 400;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: var(--danger); }
.field em { font-style: normal; font-weight: 400; }
.field-error { min-height: 0; color: var(--danger); font-weight: 400; font-size: 13px; }
.field-error:empty { display: none; }
.form-note { margin: 14px 0 0; font-size: 13px; }
.form-error { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* Ściągawka konfiguracji klienta RustDesk */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 12px 0 4px; }
.kv-label { font-size: 14px; font-weight: 600; color: var(--muted); }
.kv-empty { padding: 8px 12px; font-size: 14px; }
.qr-row { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.qr { width: 180px; height: 180px; flex-shrink: 0; border-radius: 10px; background: #fff; }
.code-block + .muted, .code-block + .code-block { margin-top: 8px; }

.import-summary ul { margin: 8px 0; padding-left: 20px; }
.import-summary .errors { max-height: 220px; overflow: auto; color: var(--danger); font-size: 14px; }

.code-block {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
}
.code-block code { flex: 1; font-size: 13px; white-space: pre-wrap; word-break: break-all; }

/* ---------- Komunikaty ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 12px 18px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-3); color: var(--text); box-shadow: var(--shadow);
  font-weight: 600;
}
.toast.toast-error { border-color: var(--danger); color: var(--danger); }
.alert { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; }

/* ---------- Logowanie ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 16px;
  padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand h1 { font-size: 22px; }
.login-brand p { margin: 2px 0 0; }
.login-card .btn { min-height: 46px; font-size: 16px; }

/* ---------- Telefon ---------- */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .brand span { font-size: 16px; }
  .container { padding: 12px 12px 40px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .qr-row { flex-direction: column; align-items: flex-start; }
  .span-2 { grid-column: auto; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 18px 18px 0 0; margin: auto auto 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.clipboard-helper { position: fixed; left: -9999px; top: 0; opacity: 0; }
