:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #40895d;
  --accent-hover: #49b875;
  --widget-bg: #fff;
  --flash-bg: #fef3c7;
  --flash-success-bg: #d1fae5;
  --danger: #dc2626;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111;
    --fg: #e5e5e5;
    --muted: #999;
    --border: #333;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --widget-bg: #1a1a1a;
    --flash-bg: #422006;
    --flash-success-bg: #064e3b;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4em 0.8em;
  border-radius: var(--radius);
}
button:hover { background: var(--accent-hover); }

input, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  border-radius: var(--radius);
  width: 100%;
}
textarea { resize: vertical; }

/* Auth pages */
.auth-page {
  max-width: 360px;
  margin: 0 auto;
  min-height: 100vh;
  align-content: center;
}
.auth-page h1 { 
  position: relative;
  margin-bottom: 1.5rem; 
  font-size: 2rem; }
.auth-page h1::before {
  content: '';
  position: absolute;
  top: 50%;
  right: calc(100% + 0.5rem);
  transform: translateY(-50%);
  background: transparent url('smiley.gif') no-repeat center center;
  width: 24px; height: 24px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
}
.auth-alt { margin-top: 1rem; color: var(--muted); }

/* Flash messages */
.flash { background: var(--flash-bg); padding: 0.5em 0.8em; border-radius: var(--radius); margin-bottom: 0.5rem; }
.flash.success { background: var(--flash-success-bg); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.2rem; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.btn-link {
  background: none;
  color: var(--accent);
  padding: 0;
}
.btn-link:hover { text-decoration: underline; background: none; }
.inline { display: inline; }

/* Dashboard grid */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.dashboard {
  grid-template-areas: "search search search"
                        "links links links"
                        "tasks pad pad";
}

#search-widget {
  grid-area: search;
}
#links-widget {
  grid-area: links;
}
#tasks-widget {
  grid-area: tasks;
}
#scratchpad-widget {
  grid-area: pad;
}

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

/* Widgets */
.widget {
  background: var(--widget-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.widget h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
}

.widget h2 svg {
  margin-right: 0.5rem;
}

/* Widget header */
.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.btn-sm { font-size: 0.8em; }

/* Tasks textarea (bulk edit) */
.tasks-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.9em;
  line-height: 1.6;
  margin-top: 0.5rem;
}

/* Links */
.links-list { list-style: none; margin-bottom: 0.8rem; }
.links-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3em 0;
}

/* Tasks */
.task-list { list-style: none; margin-top: 0.5rem; }
.task-item {
  display: flex;
  align-items: start;
  gap: 0.4rem;
  padding: 0.3em 0;
}
.task-item span { flex: 1; }
.task-item.done span { text-decoration: line-through; color: var(--muted); }
.task-item small { color: var(--muted); margin-left: auto; font-size: 0.8em; }
.task-item button { opacity: 0.2; transition: all ease-in 250ms;}
.task-item:hover button { opacity: 0.3; }
.task-item button:hover { color: var(--danger); opacity: 1; }

/* Shared */
.inline-form {
  display: flex;
  gap: 0.4rem;
}
.inline-form input { flex: 1; }

.btn-icon {
  background: none;
  color: var(--muted);
  padding: 0.2em 0.4em;
  font-size: 1.1em;
  line-height: 1;
}
.btn-icon:hover { color: var(--danger); background: none; }
.btn-icon.check:hover { color: var(--accent); }

details summary {
  cursor: pointer;
  color: var(--muted);
  margin-top: 0.5rem;
  font-size: 0.9em;
}

/* Links toggle */
.links-toggle summary { list-style: none; }
.links-toggle summary::-webkit-details-marker { display: none; }
.empty-state { color: var(--muted); }
.empty-state .link-action { color: var(--accent); cursor: pointer; }
.empty-state .link-action:hover { text-decoration: underline; }
.links-toggle .inline-form { margin-top: 0.5rem; }

/* Settings */
.settings-page {
  max-width: 480px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}
.settings-page form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
}
.settings-page input[type="number"] { max-width: 100px; }

/* Scratchpad */
#scratchpad-widget {
  display: flex;
  flex-direction: column;
}
.scratchpad-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.scratchpad-status {
  color: var(--muted);
  font-size: 0.8em;
}
.scratchpad-status.htmx-request {
  color: var(--accent);
  font-size: 0;
}
.scratchpad-status.htmx-request::after {
  content: "Saving...";
  font-size: 0.8rem;
}
.scratchpad-header + textarea {
  flex: 1;
}
