:root {
  --ink: #1a1f2b;
  --ink-2: #2d3340;
  --ink-3: #4a5160;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #ffffff;
  --bg-soft: #f7f8fb;
  --bg-card: #ffffff;
  --brand-purple: #a85fbf;
  --brand-blue: #5b7dd9;
  --brand-teal: #3fb8c4;
  --brand-green: #7bc85f;
  --brand-lime: #c5d86d;
  --brand-gradient: linear-gradient(135deg, #a85fbf 0%, #5b7dd9 35%, #3fb8c4 65%, #7bc85f 100%);
  --radius: 14px;
  --radius-lg: 22px;
  --ease: cubic-bezier(.2,.7,.2,1);
  --shadow-sm: 0 1px 2px rgba(15,19,32,.04), 0 1px 3px rgba(15,19,32,.06);
  --shadow-md: 0 4px 12px rgba(15,19,32,.06), 0 8px 24px rgba(15,19,32,.05);
}

html[data-theme="dark"] {
  --ink: #f3f4f7;
  --ink-2: #d8dbe3;
  --ink-3: #b3b8c4;
  --muted: #8b91a1;
  --line: #2a2f3d;
  --bg: #0f1320;
  --bg-soft: #161b2c;
  --bg-card: #181d2e;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,.4);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --ink: #f3f4f7;
    --ink-2: #d8dbe3;
    --ink-3: #b3b8c4;
    --muted: #8b91a1;
    --line: #2a2f3d;
    --bg: #0f1320;
    --bg-soft: #161b2c;
    --bg-card: #181d2e;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.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; }

.brand-mark {
  margin: 0;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -.01em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Clock */
.clock-widget {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}
.clock-widget .clock-time {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.clock-widget .clock-date {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Weather */
.weather-widget {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s var(--ease), transform .15s var(--ease);
}
.weather-widget:hover { background: var(--bg-card); transform: translateY(-1px); }
.weather-widget .w-icon { font-size: 16px; line-height: 1; }
.weather-widget .w-temp { font-variant-numeric: tabular-nums; }
.topbar-actions input[type="search"] {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--ink);
  font: inherit;
  min-width: 220px;
  outline: none;
  transition: border-color .15s var(--ease);
}
.topbar-actions input[type="search"]:focus { border-color: var(--brand-blue); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all .15s var(--ease);
  color: var(--ink);
  background: transparent;
}
.btn:hover { background: var(--bg-soft); }
.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { border-color: var(--line); }
.btn-icon { padding: 8px 10px; border-color: var(--line); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-danger { color: #c44; border-color: var(--line); background: transparent; }
.btn-danger:hover { background: rgba(196,68,68,.08); }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(168,95,191,.08), transparent 60%),
    radial-gradient(900px 500px at 80% 100%, rgba(91,125,217,.08), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(360px, 92vw);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.login-card .brand-mark { font-size: 36px; margin-bottom: 24px; }
.login-card form { display: grid; gap: 12px; }
.login-card input[type="password"] {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  outline: none;
}
.login-card input[type="password"]:focus { border-color: var(--brand-blue); }
.login-card button {
  font: inherit;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  background: var(--brand-gradient);
  color: #fff;
  cursor: pointer;
}
.error { color: #c44; font-size: 14px; margin: 0; }

/* ---------- Tiles page ---------- */
.tiles-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.search-widget {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 640px;
  margin: 8px auto 40px;
  padding: 6px 8px 6px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.search-widget:focus-within {
  box-shadow: var(--shadow-md);
  border-color: transparent;
  background:
    linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
    var(--brand-gradient) border-box;
  border: 1px solid transparent;
}
.search-widget-icon { width: 22px; height: 22px; flex-shrink: 0; }
.search-widget input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  padding: 12px 4px;
  border: none;
  background: transparent;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.search-widget input::placeholder { color: var(--muted); }
.search-widget button {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--brand-gradient);
  color: #fff;
  flex-shrink: 0;
  transition: filter .15s var(--ease), transform .15s var(--ease);
}
.search-widget button:hover { filter: brightness(1.05); transform: scale(1.05); }

/* Quick apps strip */
.quick-apps {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: -20px auto 40px;
  max-width: 640px;
}
.quick-app {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.quick-app:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: transparent; }
.quick-app img { width: 18px; height: 18px; flex-shrink: 0; border-radius: 4px; }

/* Apps list (dashboard) */
.apps-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.apps-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: grab;
}
.apps-list li:active { cursor: grabbing; }
.apps-list li.dragging { opacity: .4; }
.apps-list .drag-handle {
  color: var(--muted);
  user-select: none;
  font-size: 14px;
  line-height: 1;
}
.apps-list .app-icon {
  flex-shrink: 0;
  border-radius: 4px;
  background: var(--bg);
}
.apps-list input {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  outline: none;
}
.apps-list input:hover { background: var(--bg); }
.apps-list input:focus { background: var(--bg); border-color: var(--brand-blue); }
.apps-list .app-label { flex: 0 0 160px; font-weight: 500; }
.apps-list .app-url { flex: 1; min-width: 0; }

.app-add {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.app-add input {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--ink);
  outline: none;
}
.app-add input:focus { border-color: var(--brand-blue); }
.app-add input[name="label"] { flex: 0 0 180px; }
.app-add input[name="url"] { flex: 1; min-width: 0; }

@media (max-width: 640px) {
  .apps-list li { flex-wrap: wrap; }
  .apps-list .app-label, .apps-list .app-url { flex: 1 1 100%; }
  .app-add { flex-direction: column; align-items: stretch; }
  .app-add input { flex: 1; }
}
.group { margin-bottom: 40px; }
.group-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 14px;
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 20px 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--brand-gradient);
  opacity: 0;
  transition: opacity .2s var(--ease);
  pointer-events: none;
}
.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: transparent;
}
.tile:hover::before { opacity: .04; }
.tile:hover .tile-icon { transform: scale(1.04); }
.tile-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  flex-shrink: 0;
  background: var(--bg-soft);
  padding: 6px;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
  transition: transform .2s var(--ease);
}
.tile-text { min-width: 0; width: 100%; }
.tile-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}
.tile.hidden { display: none; }

.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty p { font-size: 18px; margin-bottom: 16px; }

.powered-by {
  margin-top: 64px;
  padding: 48px 24px 64px;
  border-top: 1px solid var(--line);
  text-align: center;
  background:
    radial-gradient(800px 240px at 50% 100%, rgba(168,95,191,.06), transparent 70%),
    radial-gradient(800px 240px at 50% 100%, rgba(91,125,217,.05), transparent 70%);
}
.powered-by a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.powered-by a:hover { opacity: 1; transform: translateY(-1px); }
.powered-by span {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 600;
}
.powered-by img {
  width: 220px;
  max-width: 80vw;
  height: auto;
  display: block;
}
html[data-theme="dark"] .powered-by img {
  filter: invert(1) hue-rotate(180deg) brightness(1.1);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .powered-by img {
    filter: invert(1) hue-rotate(180deg) brightness(1.1);
  }
}

/* ---------- Dashboard ---------- */
.dash-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: grid;
  gap: 24px;
}
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}
.grid-form .full { grid-column: 1 / -1; }
.grid-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.grid-form input {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  outline: none;
  transition: border-color .15s var(--ease);
}
.grid-form input:focus { border-color: var(--brand-blue); }
.grid-form button[type="submit"] { justify-self: start; }

.cats-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cats-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: grab;
  font-size: 13px;
  transition: background .1s var(--ease), border-color .1s var(--ease);
}
.cats-list li:active { cursor: grabbing; }
.cats-list li.dragging { opacity: .4; }
.cats-list .drag-handle {
  color: var(--muted);
  user-select: none;
  font-size: 14px;
  line-height: 1;
}
.cats-list .cat-name { font-weight: 500; color: var(--ink); }

/* ---------- Share links ---------- */
.share-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.share-link {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  padding: 12px 14px;
  transition: opacity .15s var(--ease);
}
.share-link.is-disabled { opacity: .55; }
.share-link-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.share-link .share-label {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  outline: none;
  min-width: 140px;
  flex: 1;
}
.share-link .share-label:hover { background: var(--bg); }
.share-link .share-label:focus { background: var(--bg); border-color: var(--brand-blue); }
.share-link .share-stats { white-space: nowrap; }
.share-link .share-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}
.share-link-body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.share-link-body .share-url {
  grid-column: 1 / -1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.share-link-body label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
}
.share-link-body input,
.share-link-body select {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.share-link-body input:focus,
.share-link-body select:focus { border-color: var(--brand-blue); }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--line); border-radius: 20px;
  transition: background .15s var(--ease);
}
.toggle span::before {
  position: absolute; content: ''; height: 14px; width: 14px; left: 3px; bottom: 3px;
  background: var(--bg); border-radius: 50%;
  transition: transform .15s var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.toggle input:checked + span { background: var(--brand-blue); }
.toggle input:checked + span::before { transform: translateX(16px); }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
}

@media (max-width: 640px) {
  .share-link-body { grid-template-columns: 1fr; }
  .share-link .share-actions { width: 100%; justify-content: flex-end; margin-left: 0; }
}

.favs-table {
  width: 100%;
  border-collapse: collapse;
}
.favs-table th, .favs-table td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.favs-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}
.favs-table tbody tr { transition: background .1s var(--ease); }
.favs-table tbody tr:hover { background: var(--bg-soft); }
.favs-table tbody tr.dragging { opacity: .4; }
.favs-table tbody tr.drop-target { background: rgba(91,125,217,.08); }
.favs-table input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  outline: none;
}
.favs-table input:hover { background: var(--bg-soft); }
.favs-table input:focus { background: var(--bg); border-color: var(--brand-blue); }
.drag-col { width: 24px; color: var(--muted); cursor: grab; text-align: center; user-select: none; }
.drag-col:active { cursor: grabbing; }
.icon-col { width: 28px; padding-right: 0; }
.actions-col { width: 32px; text-align: right; }
.priv-col { width: 40px; text-align: center; }
.priv-col input[type="checkbox"] { cursor: pointer; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  animation: toast-in .2s var(--ease);
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 640px) {
  .topbar { flex-direction: column; gap: 12px; align-items: stretch; }
  .topbar-actions { justify-content: space-between; flex-wrap: wrap; }
  .topbar-actions input[type="search"] { min-width: 0; flex: 1; }
  .grid-form { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .favs-table { font-size: 12px; }
  .favs-table .icon-col, .favs-table .drag-col { display: none; }
}
