/* IBM Plex Mono + dark industrial terminal aesthetic */
:root {
  --bg: #0a0a0b;
  --bg-2: #111113;
  --bg-3: #18181b;
  --bg-4: #222226;
  --border: #2a2a2f;
  --border-bright: #3d3d44;
  --text: #e8e8f0;
  --text-muted: #6b6b7a;
  --text-dim: #4a4a55;
  --accent: #7c6aff;
  --accent-dim: #2d2560;
  --green: #39e88f;
  --green-dim: #0f3324;
  --red: #ff4d6a;
  --red-dim: #3a0f18;
  --amber: #f5a623;
  --amber-dim: #3a2800;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-sans: 'IBM Plex Sans', sans-serif;
  --radius: 4px;
  --radius-lg: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── LOGIN ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(124,106,255,0.08) 0%, transparent 70%),
    var(--bg);
}

.login-card {
  width: 380px;
  padding: 48px 40px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.lock-icon {
  font-size: 32px;
  color: var(--accent);
  filter: drop-shadow(0 0 12px rgba(124,106,255,0.4));
}

.login-title {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text);
  margin-bottom: 6px;
}

.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 32px;
  letter-spacing: 0.05em;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-error { color: var(--red); font-size: 11px; text-align: center; min-height: 16px; }

/* ── INPUTS ── */
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label, .form-group label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124,106,255,0.15);
}

input::placeholder { color: var(--text-dim); }

/* ── BUTTONS ── */
.btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #9180ff; box-shadow: 0 0 16px rgba(124,106,255,0.3); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { border-color: var(--border-bright); color: var(--text); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-full { width: 100%; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 6px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.btn-icon:hover { color: var(--text); background: var(--bg-4); }

/* ── LAYOUT ── */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { color: var(--accent); font-size: 20px; }
.header-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text);
}

.header-right { display: flex; align-items: center; gap: 16px; }
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.key-count { font-size: 11px; color: var(--text-muted); }

.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 10px;
}
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.group-list { list-style: none; padding: 0 8px 8px; }

.group-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  color: var(--text-muted);
}
.group-item:hover { background: var(--bg-3); color: var(--text); }
.group-item.active {
  background: var(--accent-dim);
  color: var(--text);
  border-left: 2px solid var(--accent);
}

.group-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-badge {
  font-size: 10px;
  background: var(--bg-4);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}
.group-item.active .group-badge { background: var(--accent); color: #fff; }

/* ── MAIN ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  gap: 12px;
  flex-shrink: 0;
}
.toolbar-left { display: flex; gap: 10px; flex: 1; }

.search-input {
  max-width: 260px;
  background: var(--bg-3);
}
.filter-select { width: 120px; }

/* ── TABLE ── */
.table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.key-table {
  width: 100%;
  border-collapse: collapse;
}

.key-table thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.key-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.key-table tbody tr:hover { background: var(--bg-3); }

.key-table td {
  padding: 12px 16px;
  font-size: 12px;
  vertical-align: middle;
}

td.cell-group {
  color: var(--text-muted);
  font-size: 11px;
}

td.cell-name { font-weight: 500; color: var(--text); }

td.cell-value {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 220px;
}

.value-mask {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.value-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  display: inline-block;
}
.reveal-btn {
  font-size: 11px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.reveal-btn:hover { color: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.badge-public { background: var(--green-dim); color: var(--green); }
.badge-private { background: var(--bg-4); color: var(--text-dim); }

td.cell-actions {
  text-align: right;
  white-space: nowrap;
}
.action-btns { display: flex; gap: 4px; justify-content: flex-end; }
.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.05em;
}
.action-btn:hover { border-color: var(--border-bright); color: var(--text); }
.action-btn.delete:hover { border-color: var(--red); color: var(--red); background: var(--red-dim); }

.empty-row td {
  text-align: center;
  color: var(--text-dim);
  padding: 48px;
  font-size: 12px;
}

td.cell-date { color: var(--text-dim); font-size: 11px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  width: 500px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}
.modal-sm { width: 380px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text);
}

.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }

.value-input-wrap { position: relative; }
.value-input-wrap input { padding-right: 40px; }
.toggle-vis {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

.radio-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.radio-group { display: flex; gap: 10px; }
.radio-option {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.radio-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.radio-option input[type="radio"] { display: none; }
.radio-custom {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border-bright);
  flex-shrink: 0;
  margin-top: 2px;
  transition: all 0.12s;
  position: relative;
}
.radio-option:has(input:checked) .radio-custom {
  border-color: var(--accent);
  background: var(--accent);
}
.radio-option:has(input:checked) .radio-custom::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: #fff;
  border-radius: 50%;
}
.radio-text { display: flex; flex-direction: column; }
.radio-text strong { font-size: 12px; color: var(--text); font-weight: 500; }
.radio-text small { font-size: 10px; color: var(--text-muted); }

.req { color: var(--red); }
.form-error { color: var(--red); font-size: 11px; min-height: 16px; }

.delete-warn { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.delete-warn strong { color: var(--text); }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-3);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 12px;
  color: var(--text);
  z-index: 200;
  animation: toastIn 0.2s ease;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* ── RESTRICTIONS UI ──────────────────────────────────────────────────────── */

.form-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 2px;
}
.form-section-title .optional {
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0;
}

.field-hint {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 3px;
}

/* Tag input */
.tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  min-height: 40px;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tag-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124,106,255,0.15);
}

.tags { display: contents; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}
.tag-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  padding: 0;
  line-height: 1;
  transition: color 0.1s;
}
.tag-remove:hover { color: var(--red); }

.tag-input-wrap input {
  background: none;
  border: none;
  outline: none;
  box-shadow: none;
  padding: 0;
  flex: 1;
  min-width: 160px;
  font-size: 12px;
  color: var(--text);
}
.tag-input-wrap input::placeholder { color: var(--text-dim); }

input.input-error {
  animation: shake 0.3s ease;
  border-color: var(--red) !important;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

/* Restriction badges in table */
.cell-restriction { white-space: nowrap; }

.restriction-badge {
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.restriction-badge.none {
  color: var(--text-dim);
  background: transparent;
}
.restriction-badge.active {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245,166,35,0.3);
}

.mode-pill {
  font-size: 9px;
  font-weight: 700;
  background: rgba(245,166,35,0.2);
  border-radius: 4px;
  padding: 1px 4px;
  letter-spacing: 0.05em;
}

/* Wider modal for restrictions */
.modal { width: 560px; }

/* ── CURL PANEL ──────────────────────────────────────────────────────────── */

.modal-curl {
  width: 620px;
}

.curl-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.curl-icon {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -1px;
}

.curl-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  font-family: var(--font-mono);
}

.curl-body {
  gap: 20px !important;
}

/* Section group (public / admin) */
#curl-public-section,
#curl-admin-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.curl-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.curl-section-label code {
  background: var(--bg-4);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  color: var(--amber);
}

/* Individual curl command block */
.curl-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.curl-block-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding-left: 2px;
}

.curl-code-wrap {
  position: relative;
}

.curl-code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 48px 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--green);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.6;
  margin: 0;
  /* Subtle scanline feel */
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 23px,
    rgba(255,255,255,0.015) 23px,
    rgba(255,255,255,0.015) 24px
  );
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.copy-btn.copied {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-dim);
}

/* Restrictions warning */
.curl-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--amber-dim);
  border: 1px solid rgba(245,166,35,0.25);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 11px;
  color: var(--amber);
  line-height: 1.5;
}
.notice-icon {
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* CURL action button in table */
.action-btn.curl-action {
  border-color: var(--accent-dim);
  color: var(--accent);
}
.action-btn.curl-action:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

/* ── HEADER LINKS ─────────────────────────────────────────────────────────── */
.header-link {
  text-decoration: none;
  font-size: 11px;
}
.header-link-docs {
  border-color: var(--accent);
  color: var(--accent);
}
.header-link-docs:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}
