:root {
  --paper:    #f4f1ea;
  --paper-2:  #ebe6db;
  --paper-3:  #e0d9c9;
  --ink:      #1c1a17;
  --ink-2:    #3a3630;
  --muted:    #8a8478;
  --hairline: #c9c1ad;
  --hairline-2: #d8d2c0;

  --owned:        #2f6b3a;
  --owned-fill:   #c5dcc4;
  --partial:      #2a5d8a;
  --partial-fill: #c5d8e8;
  --claimed:      #a73d2c;
  --claimed-fill: #ecc4be;
  --scanned:      #4a6b8a;
  --scanned-fill: #cbd6e4;
  --warning:      #7a6200;
  --warning-fill: #f5e8a0;
  --unknown:      #8a8478;
  --unknown-fill: #d8d2c0;
  --cold:         #6a6358;
  --cold-fill:    #b8b1a1;

  --accent:    #b34626;
  --selection: #f3e3a8;

  --mono: 'Fira Mono', ui-monospace, monospace;
  --sans: 'Avenir Next', 'Avenir', 'Nunito Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 13px; -webkit-font-smoothing: antialiased; }

.scroll { overflow: auto; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 4px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

.shell { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr auto; height: 100vh; }
.sidebar { grid-row: 1 / 3; background: var(--paper-2); border-right: 1px solid var(--hairline); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 8px; padding: 14px 15px 10px; border-bottom: 1px solid var(--hairline-2); }

.brand .name { font-weight: 600; font-size: 35px; letter-spacing: -0.2px; font-family: 'Italianno', cursive; }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav-h { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px 8px 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--ink-2); text-decoration: none; background: transparent; }
.nav-item:hover { background: var(--paper-3); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-item .icon { width: 16px; display: flex; align-items: center; justify-content: center; opacity: 0.8; flex-shrink: 0; }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--hairline); background: var(--paper); }
.topbar .crumb { font-size: 13px; font-weight: 500; }
.topbar .grow { flex: 1; }

.subbar { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--hairline); background: var(--paper); min-height: 40px; }
.subbar .meta { font-size: 12px; color: var(--muted); }
.subbar .meta b { color: var(--ink); font-weight: 500; }

.btn { padding: 4px 10px; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; font-size: 12px; cursor: pointer; font-family: var(--sans); color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--paper-3); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.state { display: inline-block; font-family: var(--mono); font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 500; letter-spacing: 0.04em; }
.state.owned   { background: var(--owned-fill);   color: var(--owned); }
.state.partial { background: var(--partial-fill); color: var(--partial); }
.state.claimed { background: var(--claimed-fill); color: var(--claimed); }
.state.scanned { background: var(--scanned-fill); color: var(--scanned); }
.state.user    { background: var(--scanned-fill); color: var(--scanned); }
.state.warning     { background: var(--warning-fill); color: var(--warning); }
.state.unconfirmed { background: var(--warning-fill); color: var(--warning); }
.state.lost        { background: var(--claimed-fill); color: var(--claimed); }
.state.unknown { background: var(--unknown-fill); color: var(--unknown); }
.state.cold    { background: var(--cold-fill);    color: var(--cold); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.table { font-family: var(--mono); font-size: 12px; }
.table .thead, .table .trow {
  display: grid;
  grid-template-columns: 90px 44px minmax(80px, 1fr) minmax(80px, 1.4fr) 80px minmax(80px, 1fr) 70px 90px;
  gap: 10px;
  padding: 5px 16px;
  align-items: center;
}
.table .trow > div { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .thead { position: sticky; top: 0; background: var(--paper); border-bottom: 1px solid var(--hairline); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); z-index: 1; }
.table .trow { border-bottom: 1px solid var(--hairline-2); cursor: pointer; }
.table .trow:hover { background: var(--paper-2); }
.table .ip { color: var(--ink); }
.table .name { color: var(--ink-2); }
.table .os { color: var(--muted); font-size: 11px; }
.table .ago { color: var(--muted); text-align: right; font-size: 11px; }

.empty { padding: 40px; text-align: center; color: var(--muted); font-size: 12px; }

/* Peek */
.peek-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.peek-overlay.open { pointer-events: auto; }
.peek-overlay .scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.18); }
.peek { position: absolute; top: 0; right: 0; bottom: 0; width: 480px; background: var(--paper); border-left: 1px solid var(--hairline); box-shadow: -8px 0 32px rgba(0,0,0,0.08); display: flex; flex-direction: column; }
.peek-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px; border-bottom: 1px solid var(--hairline); }
.peek-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.peek-head .ip { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; }
.peek-head .close { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 20px; color: var(--muted); padding: 0 6px; line-height: 1; }
.peek-head .close:hover { color: var(--ink); }
.peek-body { flex: 1; padding: 16px; overflow-y: auto; }
.peek-body h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 8px; }
.peek-body h3:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 80px 1fr; gap: 6px 10px; font-size: 12px; margin-bottom: 8px; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); }
.port-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.port-row { display: flex; align-items: baseline; gap: 8px; font-size: 12px; padding: 2px 0; }
.port-num { font-size: 11px; color: var(--ink); min-width: 60px; }
.port-svc { color: var(--ink); }
.port-ver { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item { padding: 8px 10px; background: var(--paper-2); border-radius: 4px; margin-bottom: 6px; font-size: 12px; }
.note-item .by { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.note-scope { font-size: 9px; font-weight: 600; letter-spacing: 0.05em; color: #3b82f6; background: color-mix(in srgb, #3b82f6 12%, transparent); padding: 1px 5px; border-radius: 3px; }
.note-action { background: none; border: none; cursor: pointer; font-family: var(--mono); font-size: 10px; color: var(--muted); padding: 0; opacity: 0; transition: opacity 0.1s; }
.note-item:hover .note-action { opacity: 1; }
.note-action:hover { color: var(--ink); }
.note-action.note-delete:hover { color: var(--accent); }
.note-edit-textarea { width: 100%; padding: 6px 8px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 4px; font-family: var(--mono); font-size: 11px; color: var(--ink); resize: vertical; min-height: 60px; outline: none; box-sizing: border-box; }
.note-edit-textarea:focus { border-color: var(--ink); }
.note-edit-actions { display: flex; gap: 6px; margin-top: 6px; }
.note-body p { margin: 0 0 4px; }
.note-body p:last-child { margin-bottom: 0; }
.note-body code { font-family: var(--mono); background: var(--paper-3); padding: 1px 4px; border-radius: 3px; font-size: 11px; }
.note-body pre { background: var(--paper-3); border-radius: 4px; padding: 8px; overflow-x: auto; margin: 4px 0; }
.note-body pre code { background: none; padding: 0; }
.note-body ul, .note-body ol { margin: 2px 0 4px 16px; padding: 0; }
.note-body strong { font-weight: 600; }
.note-body em { font-style: italic; }
.cred-row { display: grid; grid-template-columns: minmax(60px, max-content) 1fr max-content; gap: 10px; padding: 6px 10px; background: var(--paper-2); border-radius: 4px; margin-bottom: 4px; font-family: var(--mono); font-size: 11px; justify-items: start; align-items: center; }

/* Tabs */
.subbar .tabs { display: flex; gap: 2px; }
.subbar .tab { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; color: var(--ink-2); user-select: none; }
.subbar .tab:hover { background: var(--paper-2); }
.subbar .tab.active { background: var(--ink); color: var(--paper); }
.subbar .tab .count { font-family: var(--mono); font-size: 10px; opacity: 0.6; }
.subbar .tab.active .count { opacity: 0.7; }

/* Scans table column widths */
.scans-table .thead, .scans-table .trow { grid-template-columns: 50px minmax(80px, 1.4fr) 100px 50px 50px minmax(80px, 1fr) 32px; }
.table .thead > div { cursor: pointer; user-select: none; }
.table .thead > div:hover { color: var(--ink-2); }

/* Import page */
.import-page { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 16px; overflow: hidden; }
.import-pane { display: flex; flex-direction: column; min-height: 0; }
.import-pane h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.import-pane h3 .badge { font-family: var(--mono); font-size: 10px; padding: 1px 6px; background: var(--paper-2); border-radius: 3px; color: var(--ink-2); text-transform: none; letter-spacing: 0; }
.import-pane h3 .badge.detected { background: var(--owned-fill); color: var(--owned); }
.import-area { flex: 1; min-height: 0; padding: 10px 12px; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; font-family: var(--mono); font-size: 11px; resize: none; line-height: 1.5; color: var(--ink); }
.import-area:focus { outline: none; border-color: var(--ink); }
.preview-list { flex: 1; min-height: 0; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; padding: 6px; overflow-y: auto; }
.preview-row { display: grid; grid-template-columns: 14px 100px 110px 60px 70px 1fr; gap: 8px; padding: 4px 8px; font-family: var(--mono); font-size: 11px; align-items: center; border-radius: 3px; }
.preview-row:hover { background: var(--paper-3); }
.preview-row .op { font-weight: 700; text-align: center; }
.preview-row .op.add { color: var(--owned); }
.preview-row .op.upd { color: var(--partial); }
.preview-row .tag { font-size: 10px; padding: 1px 6px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 3px; color: var(--muted); text-align: center; white-space: nowrap; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* Event feed */
.event-list { font-size: 12px; }
.event-row {
  display: grid;
  grid-template-columns: 50px 90px minmax(120px, 1fr) 100px 80px;
  gap: 10px;
  padding: 7px 16px;
  align-items: center;
  border-bottom: 1px solid var(--hairline-2);
}
.event-row:hover { background: var(--paper-2); }
.event-badge { font-family: var(--mono); font-size: 9px; font-weight: 600; padding: 2px 5px; border-radius: 3px; letter-spacing: 0.05em; text-align: center; }
.event-type { font-size: 11px; }
.event-detail { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-source { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { font-size: 10px; text-align: right; }

/* Settings */
.settings-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.settings-card { background: var(--paper); border: 1px solid var(--hairline); border-radius: 6px; padding: 16px; }
.settings-card-head { margin-bottom: 12px; }
.settings-card-head h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink); margin: 0 0 4px; }
.settings-add-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.settings-input { flex: 1; padding: 5px 8px; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; font-size: 12px; font-family: var(--mono); color: var(--ink); outline: none; }
.settings-input:focus { border-color: var(--ink); }
.settings-error { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-top: 4px; min-height: 16px; }
.pattern-rows { display: flex; flex-direction: column; gap: 4px; }
.pattern-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--paper-2); border-radius: 4px; font-size: 12px; }
.pattern-row span { flex: 1; }
.team-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.team-chip { display: flex; align-items: center; gap: 4px; padding: 3px 6px 3px 8px; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.chip-remove { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 2px; }
.chip-remove:hover { color: var(--accent); }

/* Status grid */
.status-body { flex: 1; overflow: auto; padding: 12px 16px; }
/* --hd-band is the diagonal header's vertical extent. At 45° rotation a label's
   horizontal overflow equals its vertical rise, so the same value sizes both the
   header height and the right margin needed to keep the last label from clipping. */
.status-table { background: var(--hairline-2); border-radius: 5px; overflow: visible; position: relative; --hd-band: 140px; margin-right: var(--hd-band); }
.status-table::before { content: ""; position: absolute; top: 0; left: 0; right: calc(-1 * var(--hd-band)); height: var(--hd-band); background: var(--paper-2); border-bottom: 2px solid var(--hairline); box-sizing: border-box; }
.status-corner { background: transparent; height: var(--hd-band); }
.status-col-hd { height: var(--hd-band); position: relative; overflow: visible; padding: 0; background: transparent; }
.status-col-hd > span { position: absolute; bottom: 0; left: calc(100% - 1px); transform-origin: 0% 100%; transform: rotate(-45deg); white-space: nowrap; font-size: 10px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 8px 4px 2px; border-bottom: 1px solid var(--hairline); }
.status-team-num { background: var(--paper-2); font-size: 12px; color: var(--muted); padding: 10px 6px; text-align: right; display: flex; align-items: center; justify-content: flex-end; }
.status-cell { padding: 7px 0; cursor: pointer; background: var(--paper); min-width: 0; text-align: center; }
.status-cell.empty { cursor: default; background: var(--paper); }
.status-cell:hover:not(.empty) { filter: brightness(0.95); }
.status-cell.owned       { background: var(--owned-fill);   }
.status-cell.partial     { background: var(--partial-fill); }
.status-cell.unconfirmed { background: var(--warning-fill); }
.status-cell.lost        { background: var(--claimed-fill); }
.status-cell.scanned     { background: var(--paper-2);      }
.status-cell-ip  { font-family: var(--mono); font-size: 11px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-cell-os  { font-size: 10px; color: var(--muted); margin-top: 2px; }
.status-cell-lvl { font-family: var(--mono); font-size: 9px; font-weight: 600; letter-spacing: 0.05em; margin-top: 3px; }
.status-cell.owned       .status-cell-lvl { color: var(--owned); }
.status-cell.partial     .status-cell-lvl { color: var(--partial); }
.status-cell.unconfirmed .status-cell-lvl { color: var(--warning); }
.status-cell.lost        .status-cell-lvl { color: var(--claimed); }

/* Status bar */
.statusbar { grid-column: 2; display: flex; align-items: center; gap: 8px; padding: 6px 16px; border-top: 1px solid var(--hairline); background: var(--paper-2); font-family: var(--mono); font-size: 11px; color: var(--muted); }
.statusbar .pill { color: var(--ink); }
.statusbar .sep { color: var(--hairline); }

/* Form grid (modals) */
.form-grid { display: grid; grid-template-columns: 100px 1fr; gap: 10px; align-items: center; }
.form-label { font-size: 12px; color: var(--muted); text-align: right; font-family: var(--mono); }
.form-input { padding: 6px 10px; background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 4px; font-size: 12px; font-family: var(--mono); color: var(--ink); outline: none; width: 100%; }
.form-input:focus { border-color: var(--ink); }
.form-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }

/* Credentials table columns */
.creds-table .thead, .creds-table .trow { grid-template-columns: 36px minmax(100px, 1.4fr) minmax(100px, 1.6fr) 70px 60px 60px 70px 90px 60px 32px; }
.hosts-table { display: grid; grid-template-columns: max-content max-content max-content max-content max-content 1fr; align-items: center; }
.hosts-table.hosts-admin { grid-template-columns: max-content max-content max-content max-content max-content 1fr max-content; }
.hosts-table .thead, .hosts-table #hosts-body, .hosts-table .trow { display: contents; }
.hosts-table .thead > div { position: sticky; top: 0; background: var(--paper); padding: 5px 8px; border-bottom: 1px solid var(--hairline); z-index: 1; }
.hosts-table .trow > div { padding: 5px 8px; border-bottom: 1px solid var(--hairline-2); cursor: pointer; }
.hosts-table .thead > div:first-child, .hosts-table .trow > div:first-child { padding-left: 16px; }
.hosts-table .thead > div:last-child, .hosts-table .trow > div:last-child { padding-right: 16px; }
.hosts-table .trow:hover > div { background: var(--paper-2); }
.creds-table .trow .del-btn, .hosts-table .trow .del-btn { opacity: 0; background: none; border: none; cursor: pointer; font-size: 14px; color: var(--muted); padding: 0; line-height: 1; }
.creds-table .trow:hover .del-btn, .hosts-table .trow:hover .del-btn { opacity: 1; }
.creds-table .trow .del-btn:hover, .hosts-table .trow .del-btn:hover { color: var(--accent); }

/* API Keys */
.apikey-rows { display: flex; flex-direction: column; gap: 4px; }
.apikey-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--paper-2); border-radius: 4px; }
.apikey-info { display: flex; align-items: center; gap: 10px; }
.apikey-id { font-size: 12px; color: var(--ink); }
.apikey-banner { background: var(--owned-fill); border: 1px solid var(--owned); border-radius: 5px; padding: 12px; margin-bottom: 10px; }
.apikey-banner-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.apikey-raw-row { display: flex; align-items: center; gap: 8px; }
.apikey-raw-row code { flex: 1; font-size: 11px; padding: 5px 8px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 4px; word-break: break-all; }

.copyable { cursor: pointer; position: relative; padding-right: 18px; }
.copyable:hover { background: var(--paper-2); border-radius: 3px; }
.copyable::before { content: ''; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a8478' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") no-repeat center; opacity: 0; pointer-events: none; }
.copyable:hover::before { opacity: 1; }
.copyable.copied::after { content: 'copied'; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; padding: 2px 6px; background: var(--ink); color: var(--paper); border-radius: 3px; pointer-events: none; white-space: nowrap; }
