:root {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .03);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --radius: 12px;
  --radius-sm: 10px;
  --tile: 76px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elev: #111827;
  --card: #1a2233;
  --border: #243049;
  --border-strong: #324563;
  --text: #e6ecf5;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-soft: #1e3a8a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .4), 0 2px 6px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
input { font: inherit; }

#app { max-width: 1280px; margin: 0 auto; padding: 28px 24px 80px; }

/* ─── Header ─── */
.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.greet h1 { font-size: 28px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.02em; }
.greet .meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;
  font-size: 13.5px; color: var(--muted);
}
.greet .meta b { color: var(--text); font-weight: 600; }
.greet .meta .sep { opacity: .4; user-select: none; }
.greet .meta .m-loading { opacity: .5; }
.greet .meta .m-error { opacity: .4; }
.greet .meta .m-city,
.greet .meta .m-temp:not(.m-loading):not(.m-error) {
  cursor: pointer; border-bottom: 1px dashed transparent;
  transition: color .12s, border-color .12s;
}
.greet .meta .m-city:hover,
.greet .meta .m-temp:not(.m-loading):not(.m-error):hover {
  color: var(--text); border-bottom-color: var(--muted);
}
.wx-icon {
  width: 16px; height: 16px;
  display: inline-block; vertical-align: -3px;
  margin-right: 4px;
}
.wx-icon-lg { width: 48px; height: 48px; display: block; }
.actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elev); display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); transition: all .15s;
}
.iconbtn:hover { border-color: var(--border-strong); background: var(--card); }
.iconbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.iconbtn svg { width: 18px; height: 18px; }

.user-menu { position: relative; }
.user-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px 7px 7px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px;
  font-weight: 500; font-size: 14px;
}
.user-btn:hover { border-color: var(--border-strong); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 6px; z-index: 50;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px;
  background: none; border: 0; border-radius: 8px; font-size: 14px; text-align: left; cursor: pointer; color: var(--text);
}
.menu button:hover, .menu a:hover { background: var(--bg); }
.menu .danger { color: var(--danger); }
.menu .sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu small { color: var(--muted); font-size: 12px; padding: 6px 12px; display: block; }

/* ─── Search ─── */
.search { position: relative; margin-bottom: 28px; }
.search input {
  width: 100%; padding: 13px 16px 13px 44px; font-size: 15px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; outline: none; transition: border-color .15s;
}
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }

/* ─── Categories ─── */
.cat { margin-bottom: 32px; }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cat-head h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 0; }
.cat-head .count { font-size: 12px; color: var(--muted); }
.cat-head .cat-tools { margin-left: auto; display: none; gap: 4px; }
.editing .cat-head .cat-tools { display: inline-flex; }
.cat-head input.cat-name {
  font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
  outline: none;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); gap: 8px; }

.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px 8px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); transition: transform .12s, box-shadow .12s, border-color .12s;
  text-align: center; min-height: var(--tile);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.tile .ico {
  width: 34px; height: 34px; border-radius: 8px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-weight: 700; color: #fff; font-size: 15px;
}
.tile .ico img { width: 26px; height: 26px; object-fit: contain; }
.tile .ico-fb {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; color: #fff; font-weight: 700; font-size: 15px;
}
.tile .lbl { font-size: 11.5px; line-height: 1.2; color: var(--text); word-break: break-word; max-width: 100%; }

.tile .x {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 2px solid var(--bg); display: none;
  align-items: center; justify-content: center; font-size: 14px; line-height: 1; padding: 0;
  box-shadow: var(--shadow-sm);
}
.editing .tile .x { display: inline-flex; }
.editing .tile { cursor: grab; }
.editing .tile:active { cursor: grabbing; }

.tile.dragging { opacity: .35; }
.tile.drop-before { box-shadow: -3px 0 0 var(--accent); }
.tile.drop-after { box-shadow: 3px 0 0 var(--accent); }

.tile.add {
  border-style: dashed; background: transparent; color: var(--muted);
  display: none; align-items: center; justify-content: center; cursor: pointer;
}
.editing .tile.add { display: flex; }
.tile.add:hover { color: var(--accent); border-color: var(--accent); }
.tile.add .ico { background: transparent; color: var(--muted); font-size: 28px; }
.tile.add:hover .ico { color: var(--accent); }

.add-cat {
  display: none; padding: 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--muted); text-align: center; background: transparent; width: 100%; margin-top: 8px;
}
.editing .add-cat { display: block; }
.add-cat:hover { color: var(--accent); border-color: var(--accent); }

/* ─── Welcome / dialogs ─── */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--bg-elev); color: var(--text);
  box-shadow: 0 24px 48px rgba(0, 0, 0, .25); max-width: 440px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(4px); }
dialog .body { padding: 28px; }
dialog h2 { margin: 0 0 6px; font-size: 22px; }
dialog p { margin: 0 0 20px; color: var(--muted); font-size: 14.5px; }
dialog label { display: block; font-size: 13px; font-weight: 500; margin: 12px 0 6px; color: var(--muted); }
dialog input[type="text"], dialog input[type="url"] {
  width: 100%; padding: 11px 14px; font-size: 15px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
dialog input:focus { border-color: var(--accent); }
dialog .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
dialog button.primary {
  background: var(--accent); color: #fff; border: 0; padding: 10px 18px; border-radius: 10px; font-weight: 500;
}
dialog button.primary:hover { filter: brightness(1.05); }
dialog button.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px;
}
dialog button.ghost:hover { color: var(--text); border-color: var(--border-strong); }
dialog .profiles { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
dialog .profiles button {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 12px; text-align: left; width: 100%;
}
dialog .profiles button:hover { border-color: var(--accent); }

@media (max-width: 640px) {
  #app { padding: 20px 14px 60px; }
  .header { flex-direction: column; gap: 14px; }
  .actions { width: 100%; justify-content: flex-end; }
  .greet h1 { font-size: 22px; }
  :root { --tile: 70px; }
}
