:root {
  --bg: #0e1117;
  --surface: #161b22;
  --surface-2: #1e2530;
  --border: #2a3342;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.hidden { display: none !important; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at top, #17242b 0%, #0e1117 65%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: min(410px, 94vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.65);
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand h1 { margin: 0; font-size: 18px; }
.login-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
}
.login-field input:focus { outline: none; border-color: var(--accent); }
.login-error {
  background: rgba(248, 81, 73, 0.14);
  border: 1px solid rgba(248, 81, 73, 0.5);
  color: #ff948e;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
}
.login-submit { padding: 9px 14px; font-size: 13px; font-weight: 600; margin-top: 2px; }
.login-hint { text-align: center; padding-top: 4px; border-top: 1px solid var(--border); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 600; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}
.brand-dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.brand-dot.err { background: var(--red); box-shadow: 0 0 8px var(--red); }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11px;
  color: var(--accent);
}
.lock-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid transparent;
}
.badge-lock-free { color: var(--muted); background: var(--surface-2); border-color: var(--border); }
.badge-lock-mine { color: var(--green); background: rgba(63,185,80,0.16); border-color: rgba(63,185,80,0.45); }
.badge-lock-other { color: var(--amber); background: rgba(210,153,34,0.18); border-color: rgba(210,153,34,0.55); }
.badge-cat { color: var(--accent); background: rgba(88,166,255,0.14); border-color: rgba(88,166,255,0.4); }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn-sm { padding: 3px 9px; font-size: 11px; }
.btn-primary { background: #1f6feb; border-color: #388bfd; color: #fff; }
.btn-amber { background: rgba(210,153,34,0.16); border-color: rgba(210,153,34,0.5); color: var(--amber); }
.btn-danger-outline { color: var(--red); border-color: rgba(248,81,73,0.4); background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.small-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
}

.lib-layout {
  flex: 1;
  min-height: 0;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.lib-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lib-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.lib-toolbar-left, .lib-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.lib-search {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  width: 280px;
}
.lib-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #090c10;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.lib-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.lib-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.lib-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(42, 51, 66, 0.5);
  vertical-align: middle;
}
.lib-table tr:hover td { background: rgba(88, 166, 255, 0.05); }
.empty-cell { text-align: center; padding: 36px 12px !important; }
.item-title-main { font-weight: 600; color: var(--text); }
.item-notes { font-size: 11px; color: var(--muted); margin-top: 2px; }
.row-actions { display: inline-flex; gap: 5px; justify-content: flex-end; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal-card {
  width: min(560px, 95vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
}
.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
}
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-row-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.form-field input, .form-field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12.5px;
  font-family: inherit;
}
.form-field input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.form-field input:focus, .form-field textarea:focus { outline: none; border-color: var(--accent); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 120;
  background: #21262d;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
