:root {
  color-scheme: dark;
  --ink: #241d16;
  --paper: #eee4ce;
  --paper-deep: #ddceb0;
  --cream: #f5eddb;
  --oak-1: #1d1510;
  --oak-2: #322116;
  --oak-3: #4b3020;
  --brass: #c59646;
  --brass-light: #e0bd78;
  --green: #6f9b7c;
  --amber: #c79248;
  --red: #ac625a;
  --muted: #9f927f;
  --line: rgba(71, 48, 29, 0.2);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 75% 0%, rgba(197, 150, 70, 0.08), transparent 38rem),
    #100d0b;
  color: var(--cream);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

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

.cabinet {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025), transparent 4%, transparent 96%, rgba(0,0,0,0.28)),
    repeating-linear-gradient(96deg, rgba(255,255,255,0.012) 0 2px, transparent 2px 11px),
    var(--oak-2);
  border-right: 1px solid rgba(224, 189, 120, 0.28);
  box-shadow: 14px 0 42px rgba(0,0,0,0.32);
  z-index: 10;
}

.brand-block { display: flex; gap: 14px; align-items: center; padding: 24px 22px 18px; }
.brand-block h1 { font-family: Georgia, serif; font-size: 1.28rem; margin: 3px 0 0; letter-spacing: 0.02em; }
.eyebrow { margin: 0; color: var(--brass-light); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.17em; text-transform: uppercase; }
.crest {
  width: 72px; height: 72px; border: 1px solid var(--brass); border-radius: 50%;
  display: grid; place-items: center; color: var(--brass-light); font: 700 1.3rem Georgia, serif;
  box-shadow: inset 0 0 0 4px var(--oak-2), inset 0 0 0 5px rgba(197,150,70,0.45);
}
.crest.small { width: 50px; height: 50px; flex: 0 0 auto; font-size: 1rem; }

.search-wrap { padding: 0 18px 18px; }
.search-wrap label { display: block; margin: 0 0 7px; color: var(--muted); font-size: 0.72rem; }
input, textarea {
  width: 100%; border: 1px solid rgba(224,189,120,0.26); border-radius: 7px;
  background: rgba(10,8,7,0.55); color: var(--cream); padding: 11px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(197,150,70,0.12); }

#document-nav { overflow-y: auto; padding: 0 13px 20px; flex: 1; }
.drawer { margin: 0 0 9px; border: 1px solid rgba(224,189,120,0.15); border-radius: 7px; overflow: hidden; background: rgba(0,0,0,0.12); }
.drawer summary { list-style: none; padding: 11px 12px; cursor: pointer; color: var(--brass-light); font: 700 0.72rem Georgia, serif; letter-spacing: 0.1em; text-transform: uppercase; }
.drawer summary::-webkit-details-marker { display: none; }
.drawer summary::after { content: "+"; float: right; color: var(--muted); }
.drawer[open] summary::after { content: "−"; }
.drawer-items { border-top: 1px solid rgba(224,189,120,0.11); padding: 6px; }
.doc-link {
  display: block; width: 100%; padding: 8px 9px; border: 0; border-radius: 5px;
  text-align: left; color: #d5c9b5; background: transparent; font-size: 0.79rem;
}
.doc-link:hover, .doc-link.active { color: #fff5dc; background: rgba(197,150,70,0.14); }
.doc-link small { display: block; color: #847666; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cabinet-footer { padding: 14px 18px 20px; border-top: 1px solid rgba(224,189,120,0.16); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.secondary, .primary, .login-form button {
  border: 1px solid var(--brass); border-radius: 6px; padding: 10px 13px; color: #1d150d;
  background: linear-gradient(#dfbd7b, #b98235); font-weight: 800;
}
.secondary { background: transparent; color: var(--brass-light); }
.text-button, .close-button { border: 0; background: transparent; color: var(--muted); padding: 8px; }
.text-button:hover, .close-button:hover { color: var(--cream); }

.desk { min-width: 0; padding: 34px clamp(20px, 4vw, 70px) 80px; }
.desk-header { max-width: 1120px; margin: 0 auto 20px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.desk-header h2 { font: 700 clamp(1.55rem, 3vw, 2.3rem) Georgia, serif; margin: 6px 0 0; }
.sync-state { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.76rem; }
.sync-state > span:first-child { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }
.mobile-menu { display: none; border: 0; background: transparent; color: var(--brass-light); font-size: 1.5rem; }

.paper {
  max-width: 1120px; margin: 0 auto; padding: clamp(24px, 5vw, 64px);
  color: var(--ink); background:
    linear-gradient(rgba(255,255,255,0.18), rgba(0,0,0,0.025)),
    var(--paper);
  border: 1px solid #b49c73; border-radius: 3px; box-shadow: var(--shadow);
}
.document h1, .document h2, .document h3 { font-family: Georgia, serif; line-height: 1.18; color: #2c2117; }
.document h1 { font-size: clamp(1.8rem, 4vw, 3.1rem); margin: 0 0 0.8em; }
.document h2 { font-size: 1.55rem; margin-top: 2.1em; padding-bottom: 0.25em; border-bottom: 1px solid var(--line); }
.document h3 { font-size: 1.13rem; margin-top: 1.8em; }
.document p, .document li { line-height: 1.68; }
.document a { color: #795014; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.document code { padding: 0.14em 0.35em; border-radius: 3px; background: rgba(73,48,23,0.11); font-family: ui-monospace, monospace; font-size: 0.9em; }
.document code.internal-reference { cursor: pointer; color: #734b12; box-shadow: inset 0 -1px #a57935; }
.document code.internal-reference:hover, .document code.internal-reference:focus { color: #3f2708; background: rgba(197,150,70,0.2); outline: 2px solid rgba(197,150,70,0.35); }
.document pre { overflow-x: auto; padding: 17px; border-radius: 5px; color: #e8dcc4; background: #251d16; }
.document pre code { padding: 0; background: transparent; }
.document blockquote { margin: 1.4em 0; padding: 0.2em 1.2em; border-left: 4px solid var(--brass); background: rgba(197,150,70,0.08); }
.document table { width: 100%; border-collapse: collapse; margin: 1.4em 0 2em; font-size: 0.88rem; }
.document th, .document td { border: 1px solid rgba(71,48,29,0.22); padding: 10px; text-align: left; vertical-align: top; }
.document th { background: rgba(71,48,29,0.1); font-family: Georgia, serif; }
.document tr:nth-child(even) td { background: rgba(255,255,255,0.16); }
.document hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

.home-summary { max-width: 1120px; margin: 0 auto 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.summary-card { padding: 15px 16px; border: 1px solid rgba(224,189,120,0.25); border-radius: 7px; background: #1c1713; box-shadow: 0 10px 30px rgba(0,0,0,0.18); }
.summary-card strong { display: block; font: 700 1.35rem Georgia, serif; color: var(--brass-light); }
.summary-card span { color: var(--muted); font-size: 0.76rem; }

.search-results { max-width: 1120px; margin: 0 auto; }
.search-result { width: 100%; border: 1px solid rgba(224,189,120,0.2); border-radius: 7px; color: var(--cream); background: #1b1612; padding: 16px; margin-bottom: 10px; text-align: left; }
.search-result:hover { border-color: var(--brass); }
.search-result strong { display: block; font: 700 1.05rem Georgia, serif; }
.search-result small { color: var(--brass-light); }
.search-result p { margin: 8px 0 0; color: var(--muted); }

.upload-dialog { width: min(720px, calc(100vw - 28px)); max-height: 90vh; padding: 0; border: 1px solid var(--brass); border-radius: 9px; color: var(--cream); background: var(--oak-2); box-shadow: 0 30px 90px #000; }
.upload-dialog::backdrop { background: rgba(4,3,2,0.78); backdrop-filter: blur(3px); }
.dialog-titlebar { display: flex; justify-content: space-between; align-items: start; padding: 20px 22px; border-bottom: 1px solid rgba(224,189,120,0.2); }
.dialog-titlebar h2 { margin: 5px 0 0; font-family: Georgia, serif; }
.close-button { font-size: 1.8rem; line-height: 1; }
.upload-body { padding: 22px; overflow-y: auto; }
.upload-body > label, .field-row label { display: block; color: var(--muted); font-size: 0.76rem; }
.upload-body input, .upload-body textarea { margin-top: 7px; }
.field-row { display: grid; grid-template-columns: 1fr 1.3fr; gap: 12px; margin-bottom: 16px; }
.drop-zone { margin: 17px 0; min-height: 130px; display: grid !important; place-items: center; text-align: center; padding: 20px; border: 1px dashed var(--brass); border-radius: 8px; background: rgba(0,0,0,0.18); cursor: pointer; }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }
.drop-zone strong { color: var(--brass-light); font-size: 1rem; }
.drop-zone span { display: block; margin-top: 6px; color: var(--muted); }
.upload-item { padding: 10px 0; border-top: 1px solid rgba(224,189,120,0.12); }
.upload-item-row { display: flex; justify-content: space-between; gap: 12px; font-size: 0.8rem; }
.progress { height: 5px; margin-top: 7px; border-radius: 5px; overflow: hidden; background: #0f0c09; }
.progress span { display: block; width: 0; height: 100%; background: var(--brass); transition: width 0.15s; }
.upload-status { color: var(--brass-light); min-height: 1.4em; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(circle at center, #3a2719, #100d0b 62%); }
.login-card { width: min(430px, 100%); padding: 40px; text-align: center; border: 1px solid rgba(224,189,120,0.35); border-radius: 8px; background: linear-gradient(rgba(255,255,255,0.025), rgba(0,0,0,0.12)), var(--oak-2); box-shadow: var(--shadow); }
.login-card .crest { margin: 0 auto 20px; }
.login-card h1 { margin: 8px 0; font: 700 2rem Georgia, serif; }
.login-copy { color: var(--muted); }
.login-form { margin-top: 26px; text-align: left; }
.login-form label { display: block; color: var(--muted); font-size: 0.78rem; }
.login-form input { margin: 7px 0 12px; }
.login-form button { width: 100%; margin-top: 8px; }
.login-error { color: #e58e83; font-size: 0.8rem; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .cabinet { position: fixed; left: 0; width: min(330px, 88vw); transform: translateX(-103%); transition: transform 0.22s ease; }
  .cabinet.open { transform: translateX(0); }
  .desk { padding: 20px 14px 50px; }
  .desk-header { align-items: center; }
  .mobile-menu { display: block; }
  .home-summary { grid-template-columns: 1fr; }
  .paper { padding: 24px 18px; overflow-x: auto; }
  .field-row { grid-template-columns: 1fr; }
}
