/* Design system — cool monochrome (dr-page) + soft elevation */
:root {
  --background: oklch(0.99 0 0);
  --foreground: oklch(0.15 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.15 0 0);
  --primary: oklch(0.15 0 0);
  --primary-foreground: oklch(0.99 0 0);
  --secondary: oklch(0.95 0 0);
  --secondary-foreground: oklch(0.15 0 0);
  --muted: oklch(0.92 0 0);
  --muted-foreground: oklch(0.5 0 0);
  --accent: oklch(0.88 0 0);
  --accent-foreground: oklch(0.15 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.88 0 0);
  --input: oklch(0.88 0 0);
  --ring: oklch(0.15 0 0);
  --radius: 0.75rem;
  --sidebar: oklch(0.985 0 0);
  --shadow-xs: 0 1px 2px rgba(26, 26, 26, 0.04);
  --shadow-sm: 0 1px 2px rgba(26, 26, 26, 0.05), 0 2px 6px rgba(26, 26, 26, 0.04);
  --shadow-md: 0 2px 4px rgba(26, 26, 26, 0.05), 0 6px 16px rgba(26, 26, 26, 0.06);
  --shadow-card: 0 1px 2px rgba(26, 26, 26, 0.04), 0 8px 24px rgba(26, 26, 26, 0.06);
  --shadow-card-hover: 0 4px 8px rgba(26, 26, 26, 0.05), 0 12px 32px rgba(26, 26, 26, 0.08);
  --font-sans: "Nunito", ui-sans-serif, system-ui, sans-serif;
  --font-serif: "Playfair Display", ui-serif, Georgia, serif;
  --font-display: "DM Serif Display", ui-serif, Georgia, serif;
  --font-emphasis: "Lato", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Roboto Mono", ui-monospace, monospace;
  --topbar-h: 4.25rem;
  --rail-w: 15.5rem;
  --ficha-w: 22rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: var(--border);
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
  background: none;
  border: 0;
}

strong,
b {
  font-family: var(--font-emphasis);
  font-weight: 600;
}

#app {
  height: 100%;
}

/* Auth gate */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.gate__card {
  width: min(28rem, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow-card);
  padding: 2rem 1.75rem;
  display: grid;
  gap: 1rem;
}

.gate__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin: 0;
}

.gate h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2.1rem;
  margin: 0;
  letter-spacing: 0.01em;
}

.gate p {
  margin: 0;
  color: var(--muted-foreground);
}

.field {
  display: grid;
  gap: 0.35rem;
  font-family: var(--font-emphasis);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted-foreground);
}

.field input,
.field select {
  height: 2.55rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input);
  border-radius: 0.65rem;
  background: var(--background);
  font-family: var(--font-sans);
  font-weight: 400;
}

.field input:focus,
.field select:focus,
.search input:focus {
  outline: 2px solid color-mix(in oklab, var(--ring) 35%, transparent);
  outline-offset: 1px;
}

a.btn {
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.45rem;
  padding: 0 1rem;
  border-radius: 0.7rem;
  font-family: var(--font-emphasis);
  font-weight: 600;
  font-size: 0.88rem;
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn--primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn--ghost {
  background: var(--secondary);
  color: var(--foreground);
  border-color: var(--border);
}

.btn--danger {
  background: color-mix(in oklab, var(--destructive) 12%, var(--card));
  color: var(--destructive);
  border-color: color-mix(in oklab, var(--destructive) 28%, var(--border));
}

.btn--sm {
  height: 2rem;
  padding: 0 0.7rem;
  font-size: 0.78rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Shell */
.shell {
  height: 100%;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem 0 1.25rem;
  border-bottom: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: color-mix(in oklab, var(--background) 88%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: inherit;
}

.brand span {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin-left: 0.55rem;
  vertical-align: middle;
}

.search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 36rem;
  width: 100%;
  height: 2.55rem;
  padding: 0 0.85rem;
  border: 1px solid var(--input);
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-xs);
}

.search input {
  flex: 1;
  border: 0;
  background: transparent;
  min-width: 0;
  font-size: 0.95rem;
}

.search input:focus {
  outline: none;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.workspace {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--ficha-w);
  min-height: 0;
}

.rail,
.ficha {
  min-height: 0;
  overflow: auto;
}

.rail {
  border-right: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: var(--sidebar);
  padding: 1rem 0.85rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rail__label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 0.65rem 0.7rem 0.35rem;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  color: var(--foreground);
}

.rail-item[aria-current="true"] {
  background: var(--card);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}

.rail-item:hover {
  background: color-mix(in oklab, var(--secondary) 70%, transparent);
}

.rail-item__icon {
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  border-radius: 0.45rem;
  background: var(--secondary);
  font-size: 0.85rem;
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  position: relative;
}

.crumbs,
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.75rem 1.1rem 0;
  flex-wrap: wrap;
}

.crumb {
  font-family: var(--font-emphasis);
  font-size: 0.85rem;
  color: var(--muted-foreground);
  padding: 0.2rem 0.35rem;
  border-radius: 0.4rem;
}

.crumb:hover,
.crumb[aria-current="true"] {
  color: var(--foreground);
}

.crumb[aria-current="true"] {
  font-weight: 700;
}

.sep {
  color: var(--border);
}

.toolbar {
  padding-top: 0.45rem;
  padding-bottom: 0.55rem;
  justify-content: space-between;
}

.toolbar__left,
.toolbar__right {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.listing {
  min-height: 0;
  overflow: auto;
  padding: 0.35rem 1.1rem 2rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  font-weight: 400;
  text-align: left;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--background);
}

.table td {
  padding: 0.62rem 0.7rem;
  border-bottom: 1px solid color-mix(in oklab, var(--border) 55%, transparent);
  vertical-align: middle;
}

.row {
  cursor: pointer;
}

.row:hover {
  background: color-mix(in oklab, var(--secondary) 55%, transparent);
}

.row.is-selected {
  background: var(--secondary);
}

.row__name {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.row__name strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-file {
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.5rem;
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  flex: none;
  font-size: 0.85rem;
}

.muted {
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.85rem;
}

.tile {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 0.9rem;
  box-shadow: var(--shadow-xs);
  padding: 0.9rem 0.8rem 0.8rem;
  display: grid;
  gap: 0.55rem;
  cursor: pointer;
  min-height: 7.5rem;
}

.tile:hover {
  box-shadow: var(--shadow-card);
}

.tile.is-selected {
  border-color: var(--foreground);
}

.tile strong {
  font-size: 0.85rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.empty {
  margin: 2.5rem auto;
  max-width: 28rem;
  text-align: center;
  color: var(--muted-foreground);
}

.empty h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--foreground);
  margin: 0 0 0.4rem;
}

.ficha {
  border-left: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  padding: 1.1rem 1.1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: color-mix(in oklab, var(--sidebar) 70%, var(--card));
}

.ficha__kicker {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin: 0;
}

.ficha h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.35rem;
  margin: 0.15rem 0 0;
  word-break: break-word;
}

.preview {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  min-height: 9rem;
  display: grid;
  place-items: center;
}

.preview img,
.preview video {
  max-width: 100%;
  max-height: 16rem;
  display: block;
}

.preview audio,
.preview video {
  width: 100%;
}

.preview pre,
.preview iframe {
  width: 100%;
  height: 16rem;
  margin: 0;
  border: 0;
  overflow: auto;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
}

.meta {
  display: grid;
  gap: 0.45rem;
}

.meta div {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: 0.4rem;
  font-size: 0.82rem;
}

.meta dt {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.ficha__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.drop-overlay {
  display: none;
  position: absolute;
  inset: 0.6rem;
  border: 1.5px dashed var(--foreground);
  border-radius: 1rem;
  background: color-mix(in oklab, var(--card) 82%, transparent);
  place-items: center;
  font-family: var(--font-emphasis);
  font-weight: 600;
  z-index: 5;
}

.drop-overlay.is-on {
  display: grid;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--foreground);
  color: var(--primary-foreground);
  padding: 0.7rem 0.95rem;
  border-radius: 0.7rem;
  font-family: var(--font-emphasis);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  z-index: 40;
}

.menu {
  position: fixed;
  z-index: 50;
  min-width: 12rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  box-shadow: var(--shadow-card-hover);
  padding: 0.35rem;
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

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

.dialog {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, var(--foreground) 28%, transparent);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 1rem;
}

.dialog__card {
  width: min(26rem, 100%);
  background: var(--card);
  border-radius: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg, var(--shadow-card-hover));
  padding: 1.3rem;
  display: grid;
  gap: 0.85rem;
}

.dialog h3 {
  font-family: var(--font-serif);
  margin: 0;
  font-weight: 500;
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  display: inline-block;
  background: var(--muted-foreground);
}

.status-dot.is-ok {
  background: #1f8a4c;
}

.status-dot.is-bad {
  background: var(--destructive);
}

.siblings {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.siblings div {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 12.5rem 1fr;
  }
  .ficha {
    display: none;
  }
  .ficha.is-open {
    display: flex;
    position: fixed;
    inset: var(--topbar-h) 0 0 auto;
    width: min(22rem, 100%);
    z-index: 20;
    box-shadow: var(--shadow-card-hover);
  }
  .topbar {
    grid-template-columns: auto 1fr auto;
  }
}

@media (max-width: 760px) {
  :root {
    --rail-w: 0px;
  }
  .rail {
    display: none;
  }
  .rail.is-open {
    display: flex;
    position: fixed;
    inset: var(--topbar-h) auto 0 0;
    width: 15.5rem;
    z-index: 25;
    box-shadow: var(--shadow-card-hover);
  }
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 0.65rem 0.85rem;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
