:root {
  --bg: #1e2227;
  --bg-tile: #2a2f36;
  --bg-tile-hover: #333941;
  --bg-modal: #262b31;
  --border: #3a414a;
  --text: #e6e9ec;
  --text-dim: #9aa3ad;
  --accent: #3b82f6;
  --accent-hover: #2f6fd6;
  --danger: #e5484d;
  --cols: 6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- tapeta ----------
   Obraz jest kadrowany/skalowany do rozmiaru okna (background-size: cover),
   więc np. plik 4K zostanie przycięty na 3440x1440, a przy 1080p przeskalowany. */

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image: var(--wallpaper, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.has-wallpaper::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, var(--dim, 0));
}

body.has-wallpaper .topbar {
  background: rgba(0, 0, 0, 0.35);
}

/* ---------- pasek górny ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-icon { width: 26px; height: 26px; }

.brand-name {
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.2px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  flex: 1;
  min-width: 0;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.tab:hover { background: var(--bg-tile); color: var(--text); }

.tab.active {
  background: var(--bg-tile-hover);
  color: var(--text);
  font-weight: 600;
}

.tab.add-tab {
  font-size: 18px;
  padding: 5px 12px;
  line-height: 1;
}

.tab.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  color: var(--text);
}

/* ---------- wyszukiwarka ---------- */

.search-box {
  position: relative;
  flex-shrink: 0;
}

.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-box input {
  width: 200px;
  padding: 8px 10px 8px 33px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
}

.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-dim); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.user-name {
  color: var(--text-dim);
  font-size: 13px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 4px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--bg-tile); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; }

/* ---------- siatka ---------- */

/* siatka zajmuje całą szerokość okna z marginesem 5% po obu stronach;
   wielkość kafelka wynika z szerokości okna i liczby kolumn */
main {
  padding: 26px 5% 40px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 14px;
  width: 100%;
}

.dial {
  /* kafelek może być mniejszy niż kolumna (suwak w ustawieniach) —
     wtedy między kafelkami widać więcej tła */
  width: var(--tile-size, 100%);
  justify-self: center;
  container-type: inline-size; /* jednostki cqw skalują logo względem kafelka */
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  /* proporcje karty jak w oryginalnym Speed Dial 2 (~290x200 px) */
  aspect-ratio: 13 / 9;
  /* kolor i przezroczystość kafelka regulowane w Ustawieniach
     (domyślnie białe karty jak w oryginalnym Speed Dial 2) */
  background: var(--tile-bg, #ffffff);
  border: 1px solid var(--tile-border, rgba(0, 0, 0, 0.08));
  border-radius: 12px;
  text-decoration: none;
  color: var(--tile-text-hover, #202124);
  padding: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: box-shadow 0.12s, transform 0.12s, border-color 0.12s;
  touch-action: pan-y;
}

.dial:hover {
  border-color: var(--tile-border-hover, rgba(0, 0, 0, 0.16));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.dial:active { transform: scale(0.97); }

/* grafika logo ma 90% pełnej szerokości kafelka (+20px kompensuje padding
   i ramkę, bo % liczy się od wnętrza) i całą wysokość nad podpisem;
   proporcje obrazka zachowuje object-fit: contain */
.dial-icon {
  width: calc(90% + 20px);
  flex: 1 1 0;
  min-height: 0;
  object-fit: contain;
  border-radius: 8px;
  pointer-events: none;
}

/* kafelek z literą pozostaje kwadratem — rośnie do dostępnej wysokości,
   maksymalnie do 90% szerokości kafelka */
.dial-letter {
  flex: 1 1 0;
  min-height: 0;
  aspect-ratio: 1;
  max-width: calc(90% + 20px);
  border-radius: 12%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: max(14px, 32cqw);
  font-weight: 700;
  color: #fff;
  pointer-events: none;
}

/* logo tekstowe: zamiast URL ikony można wpisać słowo */
.dial-word {
  max-width: 92%;
  padding: 0.3em 0.5em;
  border-radius: 0.25em;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
  pointer-events: none;
}

.dial-title {
  font-size: clamp(12px, 1.1vw, 16px);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tile-text, #5f6368);
  pointer-events: none;
}

body.hide-titles .dial-title { display: none; }

.dial:hover .dial-title { color: var(--tile-text-hover, #202124); }

.dial-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  gap: 4px;
}

.dial:hover .dial-actions { display: flex; }

/* na ekranach dotykowych przyciski hover nie działają — jest menu po przytrzymaniu */
@media (hover: none) {
  .dial:hover .dial-actions { display: none; }
}

.dial-action {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.45);
  color: #cdd3da;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.dial-action:hover { background: rgba(0, 0, 0, 0.7); color: #fff; }
.dial-action.delete:hover { background: var(--danger); }
.dial-action svg { width: 14px; height: 14px; }

/* kafelek "+" jest przezroczysty — widać przez niego tło/tapetę */
.dial.add-dial {
  background: transparent;
  border: none;
  box-shadow: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 44px;
  font-weight: 300;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.dial.add-dial:hover {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.dial.dragging { opacity: 0.35; }

.dial.placeholder {
  background: transparent;
  border: 2px dashed var(--accent);
  box-shadow: none;
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  opacity: 0.85;
  transform: translate(-50%, -50%) scale(0.92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.empty-note {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  padding: 30px 0 6px;
  font-size: 14px;
}

/* plakietka z nazwą folderu na kafelku w wynikach wyszukiwania */
.dial-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #cdd3da;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  pointer-events: none;
}

/* ---------- logowanie ---------- */

/* bez zalogowania nie widać zakładek ani przycisków */
body.locked .tabs,
body.locked .search-box,
body.locked .topbar-actions,
body.locked main { display: none !important; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-screen[hidden] { display: none; }

.login-card { max-width: 360px; }

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  margin-bottom: 10px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  color: var(--text);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 17px;
  margin: 0;
}

/* ---------- modale ---------- */

.modal-backdrop[hidden],
.context-menu[hidden],
.toast[hidden] { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal h3 { margin: 20px 0 6px; font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.modal label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.modal input[type="text"],
.modal input[type="password"],
.modal select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
}

.modal input[type="text"]:focus,
.modal input[type="password"]:focus,
.modal select:focus { border-color: var(--accent); }

.hint { font-size: 12px; color: var(--text-dim); }
p.hint { margin: 4px 0 12px; line-height: 1.45; }
.hint code, p.hint code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 11px;
}

.sync-status { min-height: 16px; margin: 2px 0 0 !important; }
.sync-status.ok { color: #4ade80; }
.sync-status.error { color: var(--danger); }

.row-label { margin-bottom: 18px; }
.row-label span { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* suwak koloru kafelka: tło od białego (lewo) do czarnego (prawo) */
input[type="range"].range-bw {
  accent-color: #888;
  height: 8px;
  border-radius: 5px;
  -webkit-appearance: none;
  appearance: none;
  /* lewo = wartość 0 (czarny), prawo = 255 (biały) — zgodnie z pozycją suwaka */
  background: linear-gradient(to right, #000000, #ffffff);
  border: 1px solid var(--border);
}
input[type="range"].range-bw::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
input[type="range"].range-bw::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}

/* podgląd wybranego koloru kafelka obok etykiety */
.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-left: 4px;
  /* szachownica pod półprzezroczystym kolorem, by widać było przezroczystość */
  background-image:
    linear-gradient(var(--swatch-color, #fff), var(--swatch-color, #fff)),
    linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, #999 75%),
    linear-gradient(45deg, #999 25%, #ccc 25%, #ccc 75%, #999 75%);
  background-size: 100% 100%, 8px 8px, 8px 8px;
  background-position: 0 0, 0 0, 4px 4px;
}

.check-label {
  display: flex !important;
  align-items: center;
  gap: 10px;
  font-size: 14px !important;
  color: var(--text) !important;
  cursor: pointer;
}

.check-label input { accent-color: var(--accent); width: 17px; height: 17px; }

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.modal-buttons.spread { justify-content: flex-start; margin-top: 8px; }

.btn {
  padding: 9px 18px;
  font-size: 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-tile);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { background: var(--bg-tile-hover); }

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

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

/* ---------- menu kontekstowe ---------- */

.context-menu {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 5px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.context-menu button:hover { background: var(--bg-tile-hover); }
.context-menu button.danger { color: var(--danger); }
.context-menu button:disabled { color: var(--text-dim); opacity: 0.5; cursor: default; }
.context-menu button:disabled:hover { background: transparent; }
.context-menu .separator { height: 1px; background: var(--border); margin: 5px 8px; }
.context-menu .menu-heading {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 7px 12px 3px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-modal);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 11px;
  font-size: 14px;
  z-index: 70;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ---------- telefon / tablet: kafelek = samo logo, bez podpisu ---------- */

body.mobile-device .dial-title { display: none; }

body.mobile-device .dial {
  padding: 0;
  gap: 0;
}

body.mobile-device .dial-icon {
  width: 100%;
  height: 100%;
  flex: 1 1 0;
}

body.mobile-device .dial-letter {
  flex: 1 1 0;
  width: 100%;
  max-width: 100%;
  aspect-ratio: auto;
  border-radius: 0;
}

body.mobile-device .dial-word {
  max-width: 96%;
}

/* ---------- mobile ---------- */

@media (max-width: 640px) {
  .brand-name { display: none; }
  .user-name { display: none; }
  .search-box input { width: 130px; }
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  main { padding: 16px 5% 30px; }
  .grid { gap: 9px; }
  .dial { border-radius: 10px; gap: 6px; }
  .dial-title { font-size: 11px; }
}
