  :root{
    --ink: #14171F;
    --panel: #1C2029;
    --panel-alt: #191D26;
    --rule: #333A4C;
    --rule-soft: #262C3A;
    --brass: #C4A147;
    --brass-soft: #C4A14733;
    --text: #E8E4D8;
    --text-muted: #8B8FA3;
    --danger: #C0605A;
    --radius: 3px;
  }
  *{box-sizing:border-box;}
  html,body{height:100%;}
  body{
    margin:0;
    background:var(--ink);
    color:var(--text);
    font-family:'IBM Plex Sans', sans-serif;
    font-size:14px;
    -webkit-font-smoothing:antialiased;
  }
  h1,h2,h3,.serif{font-family:'Spectral', serif;}
  .mono{font-family:'IBM Plex Mono', monospace;}
  button{
    font-family:inherit;
    cursor:pointer;
  }
  input, select, textarea{
    font-family:inherit;
    font-size:13px;
    background:var(--panel-alt);
    border:1px solid var(--rule);
    color:var(--text);
    border-radius:var(--radius);
    padding:7px 9px;
  }
  input:focus, select:focus, textarea:focus, button:focus-visible{
    outline:2px solid var(--brass);
    outline-offset:1px;
  }

  /* ---------- App shell ---------- */
  #app{
    display:flex;
    flex-direction:column;
    height:100vh;
  }
  header{
    display:flex;
    align-items:baseline;
    justify-content:space-between;
    padding:18px 26px 14px;
    border-bottom:1px solid var(--rule);
    flex-shrink:0;
    flex-wrap:wrap;
    gap:10px;
  }
  header .titles h1{
    margin:0;
    font-size:23px;
    font-weight:600;
    letter-spacing:.01em;
  }
  header .titles p{
    margin:3px 0 0;
    font-size:12.5px;
    color:var(--text-muted);
  }
  header .actions{display:flex; gap:8px; align-items:center;}
  .admin-badge{
    font-size:11px; font-weight:600; letter-spacing:.02em;
    color:#1C1706; background:var(--brass);
    padding:4px 9px; border-radius:12px;
  }
  .btn{
    background:transparent;
    border:1px solid var(--rule);
    color:var(--text);
    padding:7px 13px;
    border-radius:var(--radius);
    font-size:12.5px;
    font-weight:500;
    transition:border-color .15s;
  }
  .btn:hover{border-color:var(--brass);}
  .btn-brass{
    background:var(--brass);
    border-color:var(--brass);
    color:#1C1706;
    font-weight:600;
  }
  .btn-brass:hover{filter:brightness(1.08);}
  .btn-quiet{border-color:transparent; color:var(--text-muted); padding:6px 8px;}
  .btn-quiet:hover{color:var(--text); border-color:var(--rule);}
  .btn-small{padding:4px 9px; font-size:12px;}

  #body-row{
    display:flex;
    flex:1;
    min-height:0;
  }

  /* ---------- Sidebar ---------- */
  #sidebar{
    width:250px;
    flex-shrink:0;
    padding:18px 16px;
    overflow-y:auto;
  }
  #h-resizer{
    width:6px;
    flex-shrink:0;
    cursor:col-resize;
    background:transparent;
    position:relative;
    touch-action:none;
  }
  #h-resizer::after{
    content:"";
    position:absolute;
    top:0; bottom:0; left:2px;
    width:2px;
    background:var(--rule);
  }
  #h-resizer:hover::after, #h-resizer.dragging::after{
    background:var(--brass);
  }
  #sidebar h2{
    font-size:12.5px;
    font-weight:600;
    text-transform:none;
    color:var(--text-muted);
    margin:0 0 12px;
    letter-spacing:.02em;
  }
  .thread-row{
    display:flex;
    align-items:center;
    gap:9px;
    padding:8px 6px;
    border-radius:var(--radius);
    cursor:pointer;
    border:1px solid transparent;
  }
  .thread-row:hover{border-color:var(--rule);}
  .thread-dot{
    width:11px; height:11px; border-radius:50%;
    flex-shrink:0;
    box-shadow:0 0 0 2px rgba(0,0,0,.25) inset;
  }
  .thread-row .name{flex:1; font-size:13px;}
  .thread-row.hidden-thread .name, .thread-row.hidden-thread .count{opacity:.35;}
  .thread-row .count{font-size:11px; color:var(--text-muted);}
  .thread-row .row-actions{display:none; gap:2px;}
  .thread-row:hover .row-actions{display:flex;}
  .icon-btn{
    background:none; border:none; color:var(--text-muted);
    padding:2px 4px; font-size:12px; border-radius:2px;
  }
  .icon-btn:hover{color:var(--brass);}
  #new-thread-btn{
    width:100%; margin-top:10px; text-align:left;
    color:var(--text-muted); border:1px dashed var(--rule);
    background:none; padding:8px 10px; border-radius:var(--radius); font-size:12.5px;
  }
  #new-thread-btn:hover{color:var(--brass); border-color:var(--brass);}

  #sidebar .help{
    margin-top:22px;
    padding-top:16px;
    border-top:1px solid var(--rule-soft);
    font-size:11.5px;
    line-height:1.6;
    color:var(--text-muted);
  }

  /* ---------- Main column ---------- */
  #main{
    flex:1;
    min-width:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
  }

  #v-resizer{
    height:6px;
    flex-shrink:0;
    cursor:row-resize;
    background:transparent;
    position:relative;
    touch-action:none;
  }
  #v-resizer::after{
    content:"";
    position:absolute;
    left:0; right:0; top:2px;
    height:2px;
    background:var(--rule);
  }
  #v-resizer:hover::after, #v-resizer.dragging::after{
    background:var(--brass);
  }

  #timeline-toolbar{
    display:flex;
    align-items:center;
    gap:10px;
    padding:12px 20px;
    border-bottom:1px solid var(--rule-soft);
    flex-shrink:0;
  }
  #timeline-toolbar .spacer{flex:1;}
  #timeline-toolbar .scale-label{
    font-size:11.5px; color:var(--text-muted); min-width:80px; text-align:center;
  }
  .zoom-btn{
    width:26px; height:26px;
    border:1px solid var(--rule);
    background:transparent; color:var(--text);
    border-radius:var(--radius);
    font-size:15px; line-height:1;
  }
  .zoom-btn:hover{border-color:var(--brass); color:var(--brass);}

  #timeline-wrap{
    flex-shrink:0;
    height:44%;
    min-height:220px;
    overflow-y:auto;
    overflow-x:hidden;
    position:relative;
    background:var(--panel-alt);
  }
  #timeline-svg{
    display:block;
    cursor:grab;
    user-select:none;
    touch-action:pan-y;
  }
  #timeline-svg.grabbing{cursor:grabbing;}
  #timeline-empty{
    position:absolute; inset:0;
    display:flex; align-items:center; justify-content:center;
    flex-direction:column; gap:10px;
    color:var(--text-muted);
    text-align:center;
    padding:20px;
  }
  #timeline-empty .serif{font-size:17px; color:var(--text);}

  /* ---------- Events table ---------- */
  #table-section{
    flex:1;
    min-height:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
  }
  #table-toolbar{
    display:flex; align-items:center; gap:12px;
    padding:14px 20px 10px; flex-shrink:0;
  }
  #table-toolbar h2{font-size:13px; margin:0; font-weight:600; color:var(--text-muted);}
  #table-toolbar .spacer{flex:1;}
  #table-scroll{flex:1; overflow:auto; padding:0 20px 20px;}
  table{width:100%; border-collapse:collapse; font-size:13px;}
  thead th{
    text-align:left; font-weight:500; color:var(--text-muted);
    font-size:11.5px; padding:6px 10px; border-bottom:1px solid var(--rule);
    position:sticky; top:0; background:var(--ink);
  }
  tbody td{padding:9px 10px; border-bottom:1px solid var(--rule-soft); vertical-align:top;}
  tbody tr:hover td{background:var(--panel-alt);}
  td.desc{color:var(--text-muted); max-width:340px;}
  td.name{font-weight:500;}
  .chip{
    display:inline-flex; align-items:center; gap:6px;
    font-size:12px; color:var(--text-muted);
  }
  .chip .dot{width:8px;height:8px;border-radius:50%;}
  .row-btns{display:flex; gap:4px;}
  #table-empty{padding:30px 10px; color:var(--text-muted); text-align:center;}

  /* ---------- Modal ---------- */
  #modal-backdrop{
    position:fixed; inset:0; background:rgba(10,11,16,.6);
    display:none; align-items:flex-start; justify-content:center;
    padding:60px 20px; z-index:50; overflow:auto;
  }
  #modal-backdrop.open{display:flex;}
  .modal{
    background:var(--panel);
    border:1px solid var(--rule);
    border-radius:5px;
    width:420px;
    max-width:100%;
    padding:22px 24px 20px;
  }
  .modal h3{margin:0 0 4px; font-size:18px;}
  .modal .sub{font-size:12px; color:var(--text-muted); margin:0 0 18px;}
  .field{margin-bottom:14px;}
  .field label{display:block; font-size:12px; color:var(--text-muted); margin-bottom:5px;}
  .field input, .field select, .field textarea{width:100%;}
  .field-row{display:flex; gap:10px;}
  .field-row .field{flex:1;}
  .swatches{display:flex; flex-wrap:wrap; gap:7px; margin-top:6px;}
  .swatch{
    width:22px; height:22px; border-radius:50%; cursor:pointer;
    border:2px solid transparent;
  }
  .swatch.selected{border-color:var(--text);}
  .modal-actions{
    display:flex; justify-content:space-between; align-items:center;
    margin-top:18px; padding-top:14px; border-top:1px solid var(--rule-soft);
  }
  .modal-actions .right{display:flex; gap:8px;}
  .err{color:var(--danger); font-size:12px; margin-top:8px; display:none;}

  /* ---------- Tooltip ---------- */
  #tt{
    position:fixed; pointer-events:none; z-index:60;
    background:var(--panel); border:1px solid var(--rule);
    border-radius:4px; padding:8px 11px; font-size:12px;
    max-width:260px; display:none; box-shadow:0 6px 18px rgba(0,0,0,.4);
  }
  #tt #tt-img{
    display:block; width:100%; max-height:150px; object-fit:cover;
    border-radius:3px; margin-bottom:7px;
  }
  #tt .tt-name{font-weight:600; margin-bottom:2px;}
  #tt .tt-date{color:var(--text-muted); font-family:'IBM Plex Mono', monospace; font-size:11px;}

  ::-webkit-scrollbar{width:10px; height:10px;}
  ::-webkit-scrollbar-thumb{background:var(--rule); border-radius:5px;}
  ::-webkit-scrollbar-track{background:transparent;}

  @media (pointer: coarse){
    .hint-mouse{ display:none !important; }
    .hint-touch{ display:inline !important; }
  }

  @media (max-width: 760px){
    #sidebar{width:170px;}
    .modal{width:92vw;}
  }
