/* Base styles. Colour rules: docs/design.md (dark dominates, cognac = action, no pure white, no gradients/shadows). */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.5;
  color: var(--anthrazit);
  background: var(--creme);
}

h1, h2 { font-family: var(--font-serif); font-weight: 400; color: var(--nachtblau); margin: 0; }
h3, h4 { font-family: var(--font-sans); font-weight: 500; color: var(--nachtblau); margin: 0; }
p { margin: 0; }
a { color: var(--nachtblau); text-decoration-color: var(--cognac); text-underline-offset: 3px; }
.muted { color: var(--anthrazit); font-size: 0.875rem; }

.dark { background: var(--nachtblau); color: var(--creme); }
.dark h1, .dark h2, .dark h3, .dark h4, .dark p { color: var(--creme); }
.dark .muted { color: var(--stahlgrau); }
.dark a { color: var(--cognac); }

:focus-visible { outline: 2px solid var(--cognac); outline-offset: 2px; }

/* Buttons – min. 44 px touch target */
button { font: inherit; cursor: pointer; }
.btn, .cta {
  min-height: 44px;
  padding: 0 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.cta { background: var(--cognac); color: var(--nachtblau); }
.cta:hover { border-color: var(--nachtblau); }
.btn { background: transparent; color: var(--nachtblau); border-color: var(--anthrazit); }
.btn:hover { background: var(--stone); }
.dark .btn { color: var(--creme); border-color: var(--stahlgrau); }
.dark .btn:hover { background: var(--tiefblau); }
.btn-plain { background: transparent; border: 0; color: inherit; min-height: 44px; min-width: 44px; border-radius: var(--radius-sm); }
.btn-plain:hover { background: var(--stone); }
button:disabled { opacity: 0.6; cursor: default; }

/* Forms */
label { display: block; font-weight: 500; font-size: 0.9375rem; margin: 1rem 0 0.35rem; }
input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  min-height: 44px;
  padding: 0 0.75rem;
  font: inherit;
  color: var(--anthrazit);
  background: var(--creme);
  border: 1px solid var(--anthrazit);
  border-radius: var(--radius-sm);
}
.hint { font-size: 0.8125rem; margin-top: 0.3rem; }
.form-error { color: var(--status-bad); font-weight: 500; margin-top: 0.75rem; }
.dark .form-error { color: var(--creme); background: var(--status-bad); padding: 0.5rem 0.75rem; border-radius: var(--radius-sm); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 380px; }
.login h1 { font-size: 2.25rem; margin-bottom: 0.25rem; }
.login .cta { width: 100%; margin-top: 1.5rem; }
.login .accent-line { width: 48px; height: 2px; background: var(--cognac); margin: 1.25rem 0 0.5rem; border: 0; }

/* App shell */
.topbar {
  min-height: 64px;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 1rem;
}
.brand { font-family: var(--font-serif); font-size: 1.375rem; color: var(--creme); }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; }
.topbar-user .muted { display: none; }

.layout { display: grid; grid-template-columns: 1fr; gap: 1.5rem; padding: 1.5rem 1rem 3rem; max-width: 1400px; margin: 0 auto; }

.sidebar h2 { font-size: 1.25rem; margin-bottom: 0.75rem; }
.workspace-list { list-style: none; margin: 0 0 0.75rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.workspace-list button {
  min-height: 44px; padding: 0 0.9rem; width: 100%; text-align: left;
  background: transparent; color: var(--nachtblau); border: 1px solid var(--stone); border-radius: var(--radius-sm);
}
.workspace-list button:hover { background: var(--stone); }
.workspace-list button[aria-current="true"] { background: var(--stone); border-color: var(--cognac); font-weight: 500; }

.content-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.content-head h1 { font-size: 1.75rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.filters label { margin: 0 0 0.25rem; font-size: 0.8125rem; }
.filters select { min-width: 170px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.tile {
  position: relative;
  background: var(--stone);
  border-radius: var(--radius-md);
  border: 1px solid var(--stone);
  display: flex; flex-direction: column;
  min-height: 230px;
}
.tile-preview {
  height: 120px; margin: 0.6rem; border-radius: var(--radius-sm);
  background: var(--creme);
  display: grid; place-items: center;
  font-size: 0.8125rem; color: var(--anthrazit);
}
.tile-body { padding: 0 0.9rem 0.9rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.tile-title { font-size: 1rem; font-weight: 500; color: var(--nachtblau); padding-right: 2.5rem; overflow-wrap: anywhere; }
.tile-link { color: var(--nachtblau); text-decoration: none; }
/* Stretched link: the whole tile opens the editor; menu button sits above it */
.tile-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius-md); }
.tile:hover { border-color: var(--cognac); }
.tile-link:focus-visible { outline: none; }
.tile:has(.tile-link:focus-visible) { outline: 2px solid var(--cognac); outline-offset: 2px; }
.tile-menu-button, .menu { z-index: 2; }
.tile-meta { font-size: 0.8125rem; color: var(--anthrazit); margin-top: auto; }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; list-style: none; margin: 0; padding: 0; }
.tag { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--creme); color: var(--anthrazit); }

.tile-new {
  background: transparent; border: 1px dashed var(--anthrazit); color: var(--nachtblau);
  align-items: center; justify-content: center; gap: 0.5rem; font-weight: 500; cursor: pointer;
}
.tile-new:hover { border-style: solid; border-color: var(--cognac); }
.tile-new .plus { font-family: var(--font-serif); font-size: 2.5rem; line-height: 1; color: var(--cognac); }

.tile-menu-button { position: absolute; top: 132px; right: 0.4rem; font-size: 1.25rem; line-height: 1; }
.menu {
  position: absolute; top: 172px; right: 0.6rem; z-index: 5 !important;
  list-style: none; margin: 0; padding: 0.3rem;
  background: var(--creme); border: 1px solid var(--anthrazit); border-radius: var(--radius-sm);
  min-width: 170px;
}
.menu button { width: 100%; min-height: 44px; text-align: left; padding: 0 0.75rem; background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--nachtblau); }
.menu button:hover { background: var(--stone); }

.empty { padding: 2rem; border: 1px dashed var(--anthrazit); border-radius: var(--radius-md); max-width: 560px; }
.empty h2 { font-size: 1.375rem; margin-bottom: 0.5rem; }
.empty .cta { margin-top: 1rem; }

/* Dialogs */
dialog {
  border: 0; border-radius: var(--radius-lg); padding: 1.5rem;
  width: min(440px, calc(100vw - 2rem));
  background: var(--creme); color: var(--anthrazit);
}
dialog::backdrop { background: rgba(15, 30, 53, 0.6); }
dialog h2 { font-size: 1.5rem; }
.dialog-text { margin-top: 0.75rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--nachtblau); color: var(--creme);
  padding: 0.75rem 1.1rem; border-radius: var(--radius-sm); max-width: calc(100vw - 2rem);
}
.toast[hidden] { display: none; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (min-width: 640px) {
  .topbar { padding: 0 1.5rem; }
  .topbar-user .muted { display: inline; }
  .layout { padding: 2rem 1.5rem 3rem; }
}

@media (min-width: 1024px) {
  .layout { grid-template-columns: 260px 1fr; gap: 2rem; }
  .workspace-list { flex-direction: column; flex-wrap: nowrap; }
}
