:root {
  --ink: #000000;
  --muted: #767676;
  --paper: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f5f5f5;
  --line: #e5e5e5;
  --charcoal: #111111;
  --rust: #000000;
  --olive: #000000;
  --blue: #000000;
  --gold: #000000;
  --accent: #000000;
  --rail-width: 260px;
  --rail-collapsed: 80px;
  --topbar-height: 72px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --ink: #ffffff;
  --muted: #999999;
  --paper: #000000;
  --surface: #0a0a0a;
  --surface-alt: #1a1a1a;
  --line: #333333;
  --charcoal: #ffffff;
  --rust: #ffffff;
  --olive: #ffffff;
  --blue: #ffffff;
  --gold: #ffffff;
  --accent: #ffffff;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, "Inter", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
}

.app-shell.rail-collapsed {
  grid-template-columns: var(--rail-collapsed) minmax(0, 1fr);
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 1rem 0.75rem;
  overflow: hidden;
}

.rail-brand,
.rail-nav a,
.rail-toggle {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 0.7rem;
}

.rail-brand {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 2px solid #e8503f;
  border-radius: 50%;
  box-shadow: 6px 0 0 -2px #2f8fbd, -4px 5px 0 -2px #f0b12b, 2px -5px 0 -2px #7f5fbf;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rail-nav:not(.rail-nav-bottom) {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.rail-nav a {
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.rail-nav a:hover,
.rail-nav a.active {
  background: var(--charcoal);
  color: #fffdf8;
}

html[data-theme="dark"] .rail-nav a:hover,
html[data-theme="dark"] .rail-nav a.active {
  background: var(--surface-alt);
  color: var(--ink);
}

/* ── Rail expandable sections ── */

.rail-section {
  display: flex;
  flex-direction: column;
}

.rail-section-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.rail-section-header {
  flex: 1;
  min-width: 0;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.rail-chevron {
  flex: 0 0 24px;
  width: 24px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.6rem;
  padding: 0;
  transition: color 0.12s;
}
.rail-chevron:hover { color: var(--ink); background: var(--surface-alt); }
.rail-chevron::after { content: '▸'; }
.rail-section.expanded .rail-chevron::after { content: '▾'; }

.app-shell.rail-collapsed .rail-chevron { display: none; }

.rail-subitems {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.25rem 0 0.25rem 1rem;
  padding: 0.5rem 0 0.5rem 0.75rem;
  border-left: 2px solid var(--line);
  overflow-y: auto;
}

.rail-section.expanded .rail-subitems {
  display: flex;
}

.app-shell.rail-collapsed .rail-subitems {
  display: none !important;
}

.rail-subitems .sidebar-section {
  gap: 0;
}

.rail-subitems .sidebar-section h4 {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.rail-subitems .filter-chips {
  gap: 3px;
}

.rail-subitems .chip {
  font-size: 0.72rem;
  padding: 2px 7px;
}

.rail-subitems .folder-item {
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
}

/* ── end Rail sections ── */

.rail-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.72rem;
}

.rail-toggle {
  cursor: pointer;
}

.rail-toggle span {
  width: 28px;
  height: 2px;
  display: block;
  background: currentColor;
  box-shadow: 0 7px 0 currentColor, 0 -7px 0 currentColor;
}

.app-shell.rail-collapsed .rail-label {
  display: none;
}

.app-shell.rail-collapsed .rail-brand,
.app-shell.rail-collapsed .rail-nav a,
.app-shell.rail-collapsed .rail-toggle {
  justify-content: center;
  padding: 0;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto auto;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  padding: 0.75rem clamp(1rem, 2.2vw, 2rem);
  backdrop-filter: blur(14px);
}

.global-search {
  min-width: 0;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
}

.global-search span {
  width: 18px;
  height: 18px;
  margin-left: 0.85rem;
  border: 2px solid var(--muted);
  border-radius: 50%;
  position: relative;
}

.global-search span::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: -5px;
  width: 8px;
  height: 2px;
  background: var(--muted);
  transform: rotate(45deg);
}

.global-search input {
  width: 100%;
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 0.85rem;
}

.icon-action,
.account-chip,
.logout-chip,
.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: 0 1.5rem;
  text-transform: uppercase;
  white-space: nowrap;
  border-radius: 0;
  transition: all 0.2s ease;
}

.button:hover {
  background: var(--paper);
  color: var(--ink);
}

html[data-theme="dark"] .account-chip,
html[data-theme="dark"] .button {
  color: var(--paper);
}

.yeja-theme-control {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 3px;
}

.yeja-theme-label,
.yeja-theme-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.yeja-theme-control button {
  min-height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  padding: 0 0.7rem;
  text-transform: uppercase;
}

.yeja-theme-control button:hover,
.yeja-theme-control button:focus-visible,
.yeja-theme-control button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

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

.button.secondary:hover {
  background: var(--ink);
  color: var(--paper);
}

.button.disabled,
.button:disabled {
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--muted);
  pointer-events: none;
}

.icon-action {
  width: 42px;
  padding: 0;
  background: transparent;
  color: var(--ink);
}

.logout-chip {
  background: transparent;
  color: var(--ink);
}

.icon-action span {
  width: 16px;
  height: 20px;
  border: 2px solid currentColor;
  border-radius: 10px 10px 6px 6px;
  position: relative;
}

.icon-action span::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 7px;
  height: 2px;
  background: currentColor;
  transform: translateX(-50%);
}

.app-main {
  min-height: calc(100vh - var(--topbar-height));
  padding: clamp(1rem, 2.2vw, 2rem);
}
