/* ==========================================================================
   Linea del Tempo — identità visiva "carta astronomica antica"
   Palette: inchiostro notturno + ottone inciso + verdigris + pergamena
   Type: Fraunces (display) / Inter (corpo, UI) / IBM Plex Mono (dati, date)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #12172B;
  --ink-2: #1B2340;
  --ink-3: #232C4D;
  --brass: #C9A24B;
  --brass-light: #E0BF7A;
  --verdigris: #4F8C82;
  --parch: #F1E9D8;
  --muted: #A8AFC7;
  --danger: #B0553F;

  --bg: var(--ink);
  --panel: var(--ink-2);
  --panel-2: var(--ink-3);
  --text: var(--parch);
  --text-muted: var(--muted);
  --accent: var(--brass);
  --accent-2: var(--verdigris);
  --border: rgba(201, 162, 75, 0.22);
  --shadow: 0 12px 40px rgba(0,0,0,0.45);

  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: var(--parch);
  --panel: #E9DFC7;
  --panel-2: #DED2B2;
  --text: #1A1710;
  --text-muted: #6B5E3F;
  --accent: #8A6A2A;
  --accent-2: #2F6B62;
  --border: rgba(138, 106, 42, 0.28);
  --shadow: 0 12px 34px rgba(60, 45, 10, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  transition: background 0.25s ease, color 0.25s ease;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--panel), var(--bg));
  border-bottom: 1px solid var(--border);
  z-index: 30;
  flex-wrap: nowrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.01em;
  color: var(--accent);
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand .sub { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); letter-spacing: 0.08em; text-transform: uppercase; }

.search-wrap { position: relative; flex: 1 1 180px; min-width: 90px; max-width: 320px; }
#search-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
}
#search-input::placeholder { color: var(--text-muted); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--panel-2); }
.search-result .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sr-title { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-date { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); flex: none; }

.goto-form { display: flex; align-items: center; gap: 6px; flex: none; }
.goto-form input {
  width: 108px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.goto-form button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.topbar-spacer { flex: 1; }

.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex: none;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); font-weight: 700; }
.icon-btn.danger { color: var(--danger); }

.menu-wrap { position: relative; flex: none; }
.dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 210px;
  padding: 6px;
  z-index: 40;
}
.dropdown.open { display: block; }
.dropdown button, .dropdown label.file-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 13px;
  text-align: left;
}
.dropdown button:hover, .dropdown label.file-btn:hover { background: var(--panel-2); }
.dropdown input[type=file] { display: none; }

/* ---------------- main layout ---------------- */
.main {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#timeline-canvas { display: block; width: 100%; height: 100%; background: var(--bg); }

.year-readout {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: rgba(18,23,43,0.35);
  padding: 4px 10px;
  border-radius: 20px;
  pointer-events: none;
  z-index: 5;
}
html[data-theme="light"] .year-readout { background: rgba(241,233,216,0.55); }

.zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 92px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

.minimap-wrap {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  height: 34px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  z-index: 10;
}
#minimap-canvas { width: 100%; height: 100%; display: block; cursor: pointer; }

/* ---------------- category panel ---------------- */
.category-panel {
  position: absolute;
  top: 0;
  left: -280px;
  width: 260px;
  height: 100%;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: left 0.22s ease;
  z-index: 25;
  display: flex;
  flex-direction: column;
  padding: 16px;
}
.category-panel.open { left: 0; }
.category-panel h3 {
  font-family: var(--font-display);
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#category-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.category-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 6px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.category-row:hover { background: var(--panel-2); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.cat-name { flex: 1; }
.manage-cats-link {
  margin-top: 12px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
}

/* ---------------- detail panel ---------------- */
.detail-panel {
  position: absolute;
  top: 0;
  right: -420px;
  width: min(400px, 92vw);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: right 0.24s ease;
  z-index: 26;
  overflow-y: auto;
  padding: 20px;
}
.detail-panel.open { right: 0; }
.detail-top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.category-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  padding: 3px 9px;
  border-radius: 20px;
  margin-bottom: 10px;
}
#detail-title { font-family: var(--font-display); font-size: 22px; margin: 2px 0 4px; line-height: 1.2; }
#detail-date { font-family: var(--font-mono); font-size: 12.5px; color: var(--accent); margin-bottom: 14px; display: block; }
#detail-place { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; }
.detail-section { margin-top: 16px; }
.detail-section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin: 0 0 6px; }
#detail-short { font-size: 14.5px; line-height: 1.5; }
#detail-notes { font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; color: var(--text); }
#detail-images { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
#detail-images img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
#detail-sources { display: flex; flex-direction: column; gap: 5px; }
#detail-sources a { color: var(--accent-2); font-size: 12.5px; }
.detail-actions { display: flex; gap: 8px; margin-top: 22px; }
.detail-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 600;
}
.detail-actions .danger { color: var(--danger); }

/* ---------------- modals ---------------- */
dialog {
  border: none;
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: min(560px, 94vw);
  max-height: 88vh;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 10, 20, 0.6); backdrop-filter: blur(2px); }
.modal-header {
  padding: 18px 22px 10px;
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}
.modal-body { padding: 16px 22px; overflow-y: auto; max-height: calc(88vh - 130px); }
.modal-footer {
  padding: 12px 22px 18px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 5px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13.5px;
}
.field textarea { resize: vertical; min-height: 64px; font-family: var(--font-body); }
.field-error { outline: 2px solid var(--danger) !important; }
.row { display: flex; gap: 10px; }
.row .field { flex: 1; }
.checkbox-field { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.checkbox-field input { width: auto; }

.date-block { border: 1px dashed var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.date-block > .label-strong { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 8px; display: block; }

.image-input-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.image-input-btn input { display: none; }
#image-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.img-cell { position: relative; width: 68px; height: 68px; }
.img-cell img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.img-remove {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none; font-size: 11px; line-height: 1;
}

.btn { padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); font-size: 13px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); }

/* ---------------- category manager ---------------- */
.cat-manage-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-manage-row input[type=color] { width: 32px; height: 32px; border: none; background: none; border-radius: 6px; padding: 0; }
.cat-manage-row input[type=text] { flex: 1; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 9px; }

/* ---------------- responsive ---------------- */
@media (max-width: 720px) {
  .brand .sub { display: none; }
  .goto-form input { width: 84px; }
  .search-wrap { order: 5; flex-basis: 100%; max-width: none; margin-top: 6px; }
  .topbar { flex-wrap: wrap; }
  .detail-panel { width: 100%; }
  .zoom-controls { bottom: 100px; }
}

/* ---------------- scrollbars (webkit) ---------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

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