:root {
  --bg: #0b0d13;
  --bg-soft: #111521;
  --panel: rgba(21, 27, 41, 0.92);
  --panel-solid: #151b29;
  --panel-2: #1b2333;
  --text: #e9edf6;
  --muted: #98a2b3;
  --line: rgba(255,255,255,0.11);
  --accent: #d2a851;
  --accent-2: #7c4dff;
  --danger: #ef5350;
  --ok: #66bb6a;
  --shadow: 0 20px 80px rgba(0,0,0,0.35);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); color: var(--text); }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% -10%, rgba(124, 77, 255, 0.24), transparent 32rem),
    radial-gradient(circle at 85% 5%, rgba(210, 168, 81, 0.18), transparent 30rem),
    linear-gradient(180deg, #0b0d13 0%, #0e121c 55%, #090b10 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.6; }

.hero {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.hero__glow {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(210,168,81,0.10), transparent 35%),
    repeating-linear-gradient(90deg, transparent 0 72px, rgba(255,255,255,0.025) 72px 73px);
  pointer-events: none;
}
.hero__content {
  position: relative;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  align-items: end;
  max-width: 1500px;
  margin: 0 auto;
  padding: 34px 22px 28px;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
}
h1 {
  margin: 0;
  font-size: clamp(30px, 4.2vw, 58px);
  line-height: 0.97;
  letter-spacing: -0.055em;
}
.subtitle {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
}
.status-card {
  min-width: 250px;
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
  box-shadow: var(--shadow);
}
.status-card strong { font-size: 22px; }
.status-card small { color: var(--muted); }
.save-state {
  justify-self: start;
  border: 1px solid rgba(102,187,106,0.35);
  color: #c8f7cb;
  background: rgba(102,187,106,0.11);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}
.save-state.dirty {
  border-color: rgba(210,168,81,0.45);
  color: #ffe0a3;
  background: rgba(210,168,81,0.12);
}

.layout {
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(285px, 350px) 1fr;
  gap: 22px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 14px;
}
.panel, .editor-card, .view {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 16px; }
.panel h2, .view h2, .editor-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.panel-title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  padding: 0;
  margin-bottom: 14px;
}
.collapsible:not(.open) .panel-body { display: none; }
label { display: grid; gap: 7px; margin-bottom: 12px; }
label span { color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.045);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: rgba(210,168,81,0.55);
  box-shadow: 0 0 0 4px rgba(210,168,81,0.10);
}
select option { background: #121724; color: var(--text); }
.file-label input { padding: 9px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 10px 0 0; }
code { color: #ffd98a; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,0.055);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 750;
  transition: 0.15s ease;
}
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.09); }
.btn-primary {
  border-color: rgba(210,168,81,0.55);
  background: linear-gradient(180deg, rgba(210,168,81,0.24), rgba(210,168,81,0.11));
  color: #fff3cf;
}
.btn-danger {
  border-color: rgba(239,83,80,0.55);
  color: #ffd0cf;
  background: rgba(239,83,80,0.10);
}
.btn-small { padding: 7px 10px; border-radius: 10px; font-size: 13px; }

.workspace { min-width: 0; }
.tabs {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.035);
  overflow-x: auto;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 13px;
  border-radius: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.tab.active {
  background: rgba(210,168,81,0.16);
  color: #ffe5ad;
}
.view { display: none; padding: 18px; }
.active-view { display: block; }
.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.compact-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.timeline-list { display: grid; gap: 16px; }
.year-group {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 16px;
}
.year-label {
  position: sticky;
  top: 14px;
  align-self: start;
  color: var(--accent);
  font-size: 28px;
  font-weight: 950;
  letter-spacing: -0.05em;
  text-align: right;
  padding-top: 6px;
}
.year-events {
  position: relative;
  display: grid;
  gap: 12px;
  padding-left: 18px;
}
.year-events::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: linear-gradient(180deg, rgba(210,168,81,0.7), rgba(124,77,255,0.22));
}
.event-card {
  position: relative;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.045);
  border-radius: 16px;
  padding: 14px;
}
.event-card::before {
  content: "";
  position: absolute;
  left: -24px;
  top: 23px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--cat-color, var(--accent));
  box-shadow: 0 0 0 4px rgba(255,255,255,0.08), 0 0 20px var(--cat-color, var(--accent));
}
.event-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.event-title {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
}
.event-date {
  color: #ffe0a3;
  font-weight: 900;
  white-space: nowrap;
}
.badges { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  color: #d9deea;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}
.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--cat-color, var(--accent));
}
.event-description {
  color: #d8dde8;
  line-height: 1.55;
  margin: 10px 0 0;
  white-space: pre-wrap;
}
.event-details {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.5;
}
.event-card.expanded .event-details { display: grid; gap: 8px; }
.event-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.empty-state {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.table-wrap { overflow: auto; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #ffe0a3; background: rgba(255,255,255,0.035); font-size: 13px; }
td { color: #dce2ee; }
tr:hover td { background: rgba(255,255,255,0.035); }

.editor-card { padding: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.form-grid label { margin-bottom: 0; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.rulers-list, .stats-grid { display: grid; gap: 12px; }
.ruler-card, .stat-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,0.045);
  padding: 14px;
}
.ruler-card h3, .stat-card h3 { margin: 0 0 7px; }
.ruler-card p, .stat-card p { color: var(--muted); margin: 6px 0; line-height: 1.45; }
.stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card strong { font-size: 31px; color: #ffe0a3; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: min(640px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: rgba(16, 20, 31, 0.96);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#rulerDialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-solid);
  color: var(--text);
  width: min(620px, calc(100vw - 24px));
  box-shadow: var(--shadow);
}
#rulerDialog::backdrop { background: rgba(0,0,0,0.68); }
.dialog-card { padding: 8px; }
.dialog-card h2 { margin: 0 0 16px; }

@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .hero__content { align-items: stretch; flex-direction: column; }
  .status-card { min-width: 0; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 650px) {
  .layout { padding: 12px; }
  .year-group { grid-template-columns: 1fr; gap: 8px; }
  .year-label { position: static; text-align: left; }
  .form-grid, .two-cols, .button-grid, .stats-grid { grid-template-columns: 1fr; }
  .event-head { flex-direction: column; }
  .event-date { white-space: normal; }
}

@media print {
  body { background: #fff; color: #000; }
  .sidebar, .tabs, .event-actions, .toolbar-row .compact-actions { display: none !important; }
  .layout { display: block; padding: 0; }
  .hero, .view, .event-card { box-shadow: none; background: #fff; color: #000; border-color: #aaa; }
  .view:not(.active-view) { display: none; }
  .event-description, .event-details, .subtitle, .hint, td, th { color: #000; }
}
