/* Archivio - "Dark atelier": charcoal and gold, a leather-bound archive
   rather than a cloud app. Deep stone backgrounds, warm amber accents,
   soft gold glow on the selected. */

:root {
  --stone-950: #0c0a09;   /* app background */
  --stone-900: #1c1917;   /* panels, cards, list rows */
  --stone-850: #231f1c;   /* raised surfaces */
  --stone-800: #292524;
  --stone-700: #44403c;   /* lines and borders */
  --stone-500: #78716c;   /* secondary text */
  --parchment: #e7e0d4;   /* primary text on dark */
  --amber-400: #fbbf24;   /* gold accents */
  --amber-300: #fcd34d;
  --amber-600: #d97706;
  --gold-glow: rgba(251, 191, 36, 0.16);
  --danger: #f87171;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background: var(--stone-950);
  color: var(--parchment);
}

a { color: var(--amber-400); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 1.5rem;
  background: linear-gradient(180deg, var(--stone-900), var(--stone-950));
  border-bottom: 1px solid var(--stone-700);
}
.topbar .brand { font-size: 1.15rem; color: var(--parchment); }
.topbar .brand strong { color: var(--amber-400); letter-spacing: 0.04em; }
.tagline { color: var(--stone-500); font-size: 0.85rem; font-style: italic; margin-left: 0.6rem; }
.topbar nav a, .topbar nav .who { margin-left: 0.9rem; font-size: 0.95rem; color: var(--parchment); text-decoration: none; }
.topbar nav a:hover { color: var(--amber-400); }
.topbar .who { color: var(--stone-500); }

main { padding: 1.5rem; max-width: 1280px; margin: 0 auto; }

/* ------------------------------------------------------------------ layout */
.layout { display: grid; grid-template-columns: 270px 1fr; gap: 1.5rem; }

/* ------------------------------------------------------------- sidebar tree */
.tree {
  background: var(--stone-900);
  border: 1px solid var(--stone-700);
  border-radius: 8px;
  padding: 1rem;
  align-self: start;
}
.tree .tree-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem;
}
.tree h2 {
  font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--amber-400); margin: 0;
}
.tree ul { list-style: none; padding-left: 0; margin: 0.4rem 0 0; }
.tree ul ul { padding-left: 1.1rem; }
.tree-row {
  display: flex; align-items: center; gap: 0.25rem;
  padding: 0.22rem 0.45rem; border-radius: 5px; cursor: pointer;
  color: var(--parchment); font-size: 0.95rem;
}
.tree-row:hover { background: var(--stone-850); }
.tree-row.active {
  background: var(--gold-glow);
  color: var(--amber-400);
  box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.35);
}
.tree-row .twist { width: 0.9em; text-align: center; color: var(--amber-600); user-select: none; }
.tree-row .twist.invisible { visibility: hidden; }
.tree-label.domain { font-weight: bold; }
.tree-label::before { content: "📁"; margin-right: 0.35rem; }

/* --------------------------------------------------------------- breadcrumb */
.breadcrumb { font-size: 1rem; margin-bottom: 0.7rem; color: var(--stone-500); }
.breadcrumb .crumb { cursor: pointer; color: var(--amber-400); }
.breadcrumb .crumb:hover { color: var(--amber-300); text-decoration: underline; }
.breadcrumb .crumb.current { color: var(--parchment); font-weight: bold; cursor: default; text-decoration: none; }
.breadcrumb .sep { margin: 0 0.45rem; color: var(--stone-500); }

/* ------------------------------------------------------------------ toolbar */
.toolbar { display: flex; gap: 0.6rem; align-items: center; margin: 0.6rem 0 0.9rem; flex-wrap: wrap; }
.view-toggle .toggle {
  border-radius: 5px 0 0 5px; background: var(--stone-900); color: var(--parchment);
  border: 1px solid var(--stone-700);
}
.view-toggle .toggle + .toggle { border-radius: 0 5px 5px 0; margin-left: -1px; }
.view-toggle .toggle.active {
  background: var(--amber-600); border-color: var(--amber-600); color: #1c1917; font-weight: bold;
}

button, .button {
  font-family: inherit; font-size: 0.95rem; padding: 0.4rem 1rem;
  background: var(--stone-850); color: var(--parchment);
  border: 1px solid var(--stone-700); border-radius: 5px; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--amber-600); }
button.primary, a.primary {
  background: var(--amber-400); color: #1c1917; border-color: var(--amber-400);
  font-weight: bold; text-decoration: none; display: inline-block;
}
button.primary:hover { background: var(--amber-300); }

.hint { color: var(--stone-500); font-size: 0.9rem; font-style: italic; }
#new-folder-row { display: flex; gap: 0.6rem; align-items: center; margin: 0.4rem 0; }
#new-folder-row input {
  padding: 0.35rem 0.5rem; border: 1px solid var(--amber-600); border-radius: 5px;
  min-width: 260px; font-family: inherit; font-size: 0.95rem;
  background: var(--stone-950); color: var(--parchment);
}

/* ----------------------------------------------------------- cards (grid view) */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.8rem; margin: 1rem 0;
}
.card {
  background: var(--stone-900); border: 1px solid var(--stone-700);
  border-radius: 8px; padding: 0.75rem; cursor: default; position: relative; min-height: 104px;
}
.card:hover { border-color: var(--amber-600); }
.card.selected {
  background: var(--gold-glow);
  outline: 1px solid var(--amber-400);
  box-shadow: 0 0 14px var(--gold-glow), inset 0 0 0 1px rgba(251, 191, 36, 0.4);
}
.card .card-icon { font-size: 1.7rem; color: var(--amber-400); }
.card .card-name { margin-top: 0.35rem; font-size: 0.92rem; word-break: break-word; color: var(--parchment); }
.card .card-meta { color: var(--stone-500); font-size: 0.8rem; margin-top: 0.2rem; }

/* File-type badges: dark, tuned for readability on charcoal */
.badge {
  background: var(--stone-800); color: var(--parchment);
  border: 1px solid var(--stone-700);
  border-radius: 4px; font-size: 0.7rem; padding: 0.12rem 0.45rem;
  font-family: "Consolas", monospace; letter-spacing: 0.05em;
}
.card .badge.type { position: absolute; top: 0.6rem; right: 0.6rem; }
.badge.type[data-type="PDF"]  { color: #fca5a5; border-color: #7f1d1d; }
.badge.type[data-type="XLSX"], .badge.type[data-type="XLS"] { color: #86efac; border-color: #14532d; }
.badge.type[data-type="DOCX"], .badge.type[data-type="DOC"] { color: #93c5fd; border-color: #1e3a8a; }
.badge.type[data-type="JPG"], .badge.type[data-type="JPEG"], .badge.type[data-type="PNG"],
.badge.type[data-type="HEIC"] { color: #fcd34d; border-color: #78350f; }
.badge.type[data-type="MP4"], .badge.type[data-type="MOV"] { color: #c4b5fd; border-color: #4c1d95; }

/* ------------------------------------------------------------------- tables */
.files { width: 100%; border-collapse: collapse; background: var(--stone-900); border: 1px solid var(--stone-700); border-radius: 8px; }
.files th, .files td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--stone-700); font-size: 0.95rem; }
.files tr:last-child td { border-bottom: none; }
.files th {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--amber-400); background: var(--stone-850);
}
.files tr { background: var(--stone-900); }
.files tr:hover td { background: var(--stone-850); }
.files tr.selected td { background: var(--gold-glow); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty, .notice { color: var(--stone-500); font-style: italic; }
.notice a { color: var(--amber-400); }

/* ------------------------------------------------------------ preview modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 10, 9, 0.82);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
/* The hidden attribute must win over display: flex above - otherwise
   the empty backdrop covers the page on load with nothing in it. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--stone-900); border: 1px solid var(--amber-600); border-radius: 10px;
  max-width: 900px; width: 92%; max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 0 40px var(--gold-glow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--stone-700);
}
.modal-head .modal-title { font-weight: bold; color: var(--amber-400); word-break: break-word; }
.modal-head .modal-meta { color: var(--stone-500); font-size: 0.85rem; margin-top: 0.15rem; }
.modal-body { padding: 0.8rem 1.1rem; overflow: auto; }
.modal-body iframe, .modal-body img {
  width: 100%; height: 60vh; border: 1px solid var(--stone-700); border-radius: 6px; background: white;
}
.modal-close { background: none; border: none; color: var(--stone-500); font-size: 1.4rem; cursor: pointer; }
.modal-close:hover { color: var(--amber-400); }

/* ----------------------------------------------------------------- login card */
.login-card {
  max-width: 380px; margin: 4rem auto; background: var(--stone-900);
  border: 1px solid var(--stone-700); border-radius: 10px; padding: 2rem;
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
}
.login-card h1 { color: var(--amber-400); font-weight: normal; }
.login-card label { display: block; margin: 0.8rem 0; color: var(--parchment); }
.login-card input {
  display: block; width: 100%; margin-top: 0.25rem; padding: 0.45rem;
  border: 1px solid var(--stone-700); border-radius: 5px; font-size: 0.95rem;
  background: var(--stone-950); color: var(--parchment);
}
.login-card input:focus { border-color: var(--amber-400); outline: none; }
.error { color: var(--danger); }

/* --------------------------------------------------------------- file page */
.path { color: var(--stone-500); font-size: 0.9rem; font-family: monospace; }
h1 { font-weight: normal; color: var(--parchment); }
.meta { border-collapse: collapse; background: var(--stone-900); border: 1px solid var(--stone-700); margin: 1rem 0; width: 100%; }
.meta th { text-align: right; padding: 0.4rem 0.8rem; color: var(--stone-500); font-size: 0.85rem; }
.meta td { padding: 0.4rem 0.8rem; border-bottom: 1px solid var(--stone-700); }
.preview { max-width: 100%; max-height: 560px; border: 1px solid var(--stone-700); margin-top: 1rem; }
.file-page { max-width: 860px; }
code { background: var(--stone-800); padding: 0.05rem 0.3rem; border-radius: 3px; font-size: 0.85em; color: var(--amber-300); }
.inline-form { display: flex; gap: 0.4rem; }
.upload-box { background: var(--stone-900); border: 1px dashed var(--amber-600); border-radius: 6px; padding: 0.8rem 1rem; margin: 1rem 0; }
.upload-box summary { cursor: pointer; font-weight: bold; color: var(--amber-400); }
.upload-form label { display: block; margin: 0.5rem 0; font-size: 0.9rem; }
.upload-form input, .upload-form select {
  display: block; margin-top: 0.2rem; padding: 0.35rem; border: 1px solid var(--stone-700);
  border-radius: 5px; font-size: 0.95rem; background: var(--stone-950); color: var(--parchment);
}

/* ---------------------------------------------------------- live editor */
.live-page { max-width: 960px; }
.live-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.live-head h1 { margin: 0; }
.live-status { font-size: 0.9rem; color: var(--stone-500); }
.live-status.ok { color: var(--amber-300); }
.live-status.err { color: var(--danger); }
.doc-toolbar { display: flex; gap: 0.35rem; margin: 1rem 0 0.5rem; }
.doc-toolbar button {
  background: var(--stone-800); color: var(--parchment); border: 1px solid var(--stone-700);
  border-radius: 4px; padding: 0.25rem 0.6rem; cursor: pointer; font-size: 0.9rem;
}
.doc-toolbar button:hover { border-color: var(--amber-400); }
.documento-editor, .documento-view {
  background: var(--stone-900); border: 1px solid var(--stone-700); border-radius: 8px;
  min-height: 320px; padding: 1.2rem 1.6rem; line-height: 1.55; outline: none;
}
.documento-editor:focus { border-color: var(--amber-600); }
.documento-editor h2, .documento-view h2 { color: var(--parchment); }
.documento-editor a, .documento-view a { color: var(--amber-300); }
.foglio-grid { border-collapse: collapse; margin: 0.6rem 0; background: var(--stone-950); }
.foglio-grid td, .foglio-grid th {
  border: 1px solid var(--stone-700); padding: 0; min-width: 88px; height: 30px;
  font-size: 0.9rem; color: var(--parchment); position: relative;
}
.foglio-grid td:first-child, .foglio-grid th { min-width: 36px; text-align: center;
  color: var(--stone-500); background: var(--stone-900); }
.foglio-grid td[data-computed]::after {
  content: attr(data-value); display: block; padding: 0.3rem 0.45rem; white-space: pre-wrap;
}
.foglio-grid td[data-computed] input {
  position: absolute; inset: 0; width: 100%; border: none; background: transparent;
  color: transparent; caret-color: var(--parchment); padding: 0.3rem 0.45rem; font: inherit;
}
.foglio-grid td[data-computed] input:focus { background: var(--stone-800); color: var(--parchment); }
.foglio-preview { background: var(--stone-900); border: 1px solid var(--stone-700);
  border-radius: 6px; padding: 1rem; overflow-x: auto; }
.foglio-preview code { background: transparent; color: var(--parchment); }
.template-choice {
  display: block; width: 100%; text-align: left; background: var(--stone-800);
  border: 1px solid var(--stone-700); border-radius: 6px; padding: 0.6rem 0.9rem;
  margin: 0.4rem 0; cursor: pointer; color: var(--parchment); font: inherit;
}
.template-choice:hover { border-color: var(--amber-400); }
.template-choice span { display: block; color: var(--stone-500); font-size: 0.85rem; }

/* ----------------------------------------------------------------- shares */
.share-form { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: end; margin: 0.6rem 0; }
.share-form label { font-size: 0.85rem; color: var(--stone-500); }
.share-form input, .share-form select {
  display: block; margin-top: 0.2rem; padding: 0.35rem; font: inherit;
  border: 1px solid var(--stone-700); border-radius: 5px;
  background: var(--stone-950); color: var(--parchment);
}
.share-form .check { display: flex; align-items: center; gap: 0.3rem; padding-bottom: 0.5rem; }
.share-url {
  width: 100%; min-width: 220px; padding: 0.3rem; font-size: 0.85rem;
  border: 1px solid var(--stone-700); border-radius: 4px;
  background: var(--stone-950); color: var(--amber-300);
}
.share-page { max-width: 640px; margin: 2rem auto; }
.share-page .preview { width: 100%; height: 70vh; background: var(--stone-950); }
