:root {
  color-scheme: dark light;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #4f6df5;
  --link-accent: #4f6df5;
  --error: #d64545;
  --success: #1a9e5c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card-bg: #181b22;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #262a33;
    --accent: #7c93ff;
    --link-accent: #7c93ff;
    --success: #3ecf8e;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.app-header-actions {
  display: flex;
  gap: 0.5rem;
}

button {
  font: inherit;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button:hover {
  filter: brightness(1.08);
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 1rem 1.5rem 1.5rem;
}

.filter-bar {
  padding: 1rem 1.5rem 0;
}

.filter-bar input {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

.filter-bar input:focus {
  outline: none;
  border-color: var(--link-accent);
  box-shadow: 0 0 0 1px var(--link-accent);
}

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.tag-chip {
  font-size: 0.75rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

.tag-chip--active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* The link grid: matches the dashboard's responsive 3 → 2 → 1 column layout so
   it feels identical on desktop and mobile and reflows cleanly. */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  padding: 1.5rem;
}

@media (max-width: 1000px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Tappable / clickable link buttons. Big hit-targets for touch, with a hover
   and an active press state. */
.link-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 120px;
  padding: 1.25rem 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--text);
  text-decoration: none;
  text-align: center;
  transition: transform 0.06s ease, border-color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.link-button:hover {
  border-color: var(--link-accent);
  box-shadow: 0 0 0 1px var(--link-accent);
}

.link-button:active {
  transform: scale(0.97);
}

/* A thin top accent strip when the link defines its own color. */
.link-button[style*="--link-accent"] {
  border-top: 3px solid var(--link-accent);
}

.link-button--invalid {
  opacity: 0.6;
  cursor: not-allowed;
}

.link-icon {
  font-size: 2.4rem;
  line-height: 1;
}

.link-label {
  font-size: 1rem;
  font-weight: 600;
}

.link-tags {
  font-size: 0.7rem;
  color: var(--muted);
}

.widget-empty {
  color: var(--muted);
  margin: 0;
}

/* Settings dialog — mirrors the dashboard's dialog styling. */
dialog {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: min(480px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

#settings-form h2 {
  margin-top: 0;
}

.settings-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 1rem;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

#add-link-btn {
  width: 100%;
  margin-bottom: 1rem;
}

.link-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  position: relative;
}

.link-row .settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}

.link-row .settings-field input {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.link-row .settings-field:first-of-type {
  width: 100%;
}

.link-remove-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
  line-height: 1;
}

/* Export/Import bar beneath the settings form */
.export-import-bar {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

button.secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--card-bg);
}
