:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #242424;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-muted: #666;
  --accent: #4f8ef7;
  --accent-hover: #6ba0f8;
  --danger: #e05555;
  --success: #4caf7d;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --radius: 8px;
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-hover: #f0f0f0;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #888;
  --accent: #3b7de8;
  --accent-hover: #2d6fd6;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
}

header h1 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.clock {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
}

/* ── Buttons ── */
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
  font-family: var(--font);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Tabs ── */
.tabs-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-bar::-webkit-scrollbar { display: none; }

.tab-group {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s;
  position: relative;
}

/* DnD indicators on tabs */
.tab-group.drag-before::before,
.tab-group.drag-after::after {
  content: '';
  position: absolute;
  top: 4px; bottom: 4px;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.tab-group.drag-before::before { left: -1px; }
.tab-group.drag-after::after  { right: -1px; }
.tab-group.dragging { opacity: 0.4; }

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 11px 14px;
  font-size: 0.82rem;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab-btn:hover { color: var(--text); }
.tab-group.tab-active .tab-btn { color: var(--accent); }
.tab-group.tab-active { border-bottom-color: var(--accent); }

.tab-edit-group {
  display: none;
  align-items: center;
  gap: 1px;
  padding-right: 4px;
}
.body-edit .tab-edit-group { display: flex; }

.tab-meta-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 3px 5px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  font-family: var(--font);
  line-height: 1;
}
.tab-meta-btn:hover { color: var(--text); background: var(--border); }
.tab-meta-btn.del:hover { color: var(--danger); }

.tab-add-btn {
  display: none;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-family: var(--font);
  margin: auto 0 auto 8px;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-add-btn:hover { border-color: var(--accent); color: var(--accent); }
.body-edit .tab-add-btn { display: flex; align-items: center; gap: 5px; }

/* ── Main ── */
main { flex: 1; padding: 28px 32px; }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.15s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Search ── */
.search-wrap { margin-bottom: 20px; }

.search-input {
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 7px 13px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); }

/* ── Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

/* ── Card wrap (DnD container) ── */
.card-wrap {
  position: relative;
  border-radius: var(--radius);
  transition: opacity 0.15s;
}
.card-wrap.dragging { opacity: 0.3; }
.card-wrap.drag-over::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 2px dashed var(--accent);
  border-radius: calc(var(--radius) + 2px);
  pointer-events: none;
}

/* ── Card ── */
.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  padding: 16px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: var(--shadow);
  width: 100%;
  height: 100%;
  min-height: 100px;
}
.card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(79,142,247,0.12);
}
.body-edit .card { pointer-events: none; }

.card-icon     { font-size: 1.5rem; line-height: 1; }
.card-icon-img { width: 36px; height: 36px; object-fit: contain; border-radius: 4px; }
.card-name     { font-size: 0.87rem; font-weight: 600; }
.card-desc     { font-size: 0.73rem; color: var(--text-muted); line-height: 1.4; }
.card-url {
  font-size: 0.68rem; color: var(--text-muted); opacity: 0.55;
  margin-top: auto; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; width: 100%;
}

/* ── Card overlay (edit mode) ── */
.card-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: rgba(0,0,0,0.5);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: 2;
}
.body-edit .card-overlay { display: flex; }

/* Drag handle hint */
.card-overlay::before {
  content: '⠿';
  position: absolute;
  top: 6px; right: 8px;
  color: rgba(255,255,255,0.4);
  font-size: 0.85rem;
  cursor: grab;
  user-select: none;
}
.body-edit .card-wrap { cursor: grab; }
.body-edit .card-wrap:active { cursor: grabbing; }

.ov-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  width: 30px; height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ov-btn:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--accent); }
.ov-btn.del:hover { border-color: var(--danger); color: var(--danger); }

/* ── Add card button ── */
.card-add {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 14px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  min-height: 100px;
  transition: border-color 0.15s, color 0.15s;
}
.card-add:hover { border-color: var(--accent); color: var(--accent); }
.body-edit .card-add { display: flex; }

/* ── Empty ── */
.empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 40px 0;
  text-align: center;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: modalIn 0.15s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label {
  font-size: 0.72rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* ── Icon preview row ── */
.icon-preview-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.icon-preview {
  width: 46px; height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  background: var(--bg);
  overflow: hidden;
}
.icon-preview img {
  width: 34px; height: 34px;
  object-fit: contain;
}

/* ── Icon picker ── */
.picker-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-family: var(--font);
  margin-bottom: 10px;
  transition: border-color 0.15s, color 0.15s;
}
.picker-toggle:hover,
.picker-toggle.open  { border-color: var(--accent); color: var(--accent); }
.picker-toggle .arrow { margin-left: auto; transition: transform 0.15s; }
.picker-toggle.open .arrow { transform: rotate(180deg); }

.icon-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.icon-search-input {
  display: block;
  width: 100%;
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 8px 12px;
  outline: none;
}
.icon-search-input::placeholder { color: var(--text-muted); }
.icon-search-input:focus { background: var(--surface-hover); }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 3px;
  padding: 6px;
  max-height: 196px;
  overflow-y: auto;
}

.icon-item {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.1s;
  aspect-ratio: 1;
}
.icon-item:hover  { background: var(--surface-hover); border-color: var(--border); }
.icon-item.sel    { border-color: var(--accent); background: var(--surface-hover); }
.icon-item img    { width: 30px; height: 30px; object-fit: contain; display: block; }

.icon-msg {
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 20px;
  text-align: center;
  grid-column: 1 / -1;
}

/* ── Modal actions ── */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: var(--font);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--text-muted); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 600px) {
  header, .tabs-bar, main { padding-left: 14px; padding-right: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .search-input { width: 100%; }
  .clock { display: none; }
}
