/* ==========================================================================
   ClaudeDeck — admin console styles (self-contained)
   ========================================================================== */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e9eef5;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --on-accent: #ffffff;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: 14px; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }

/* --- Buttons (shared with chat for consistency) -------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px 14px; border-radius: var(--radius-sm); font-weight: 500;
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fde2e2; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-4); }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 12px; color: var(--text-subtle); }

.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* --- Top bar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand-logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 14px;
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-spacer { flex: 1; }
.topbar-links { display: flex; align-items: center; gap: var(--sp-3); }

/* --- Layout -------------------------------------------------------------- */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; max-width: 1180px; margin: 0 auto; gap: var(--sp-5); padding: var(--sp-5); align-items: start; }

.tabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 80px; }
.tab {
  text-align: left; padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: var(--sp-5); margin-bottom: var(--sp-5);
}
.card h2 { margin: 0 0 var(--sp-1); font-size: 18px; }
.card .card-desc { color: var(--text-muted); font-size: 13px; margin: 0 0 var(--sp-4); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.section-head h2 { margin: 0; }

.note {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--text-muted);
  margin-bottom: var(--sp-4);
}
.note.warn { background: var(--warn-soft); border-color: #f3e0b5; color: #92400e; }
.note code { background: rgba(0,0,0,0.06); padding: 1px 6px; border-radius: 4px; }

.row-inline { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

/* --- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 700; }
table.data tr:last-child td { border-bottom: none; }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data td.actions .btn { margin-left: var(--sp-1); }
table.data input.cell, table.data select.cell {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
table.data input.cell:focus, table.data select.cell:focus { outline: none; border-color: var(--accent); }

/* --- Badges -------------------------------------------------------------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.on { background: var(--success-soft); color: var(--success); }
.pill.off { background: var(--surface-2); color: var(--text-muted); }
.pill.admin { background: var(--accent-soft); color: var(--accent); }

.state-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.state-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state-connected { background: var(--success-soft); color: var(--success); }
.state-failed { background: var(--danger-soft); color: var(--danger); }
.state-needs_auth { background: var(--warn-soft); color: #92400e; }
.state-unknown { background: var(--surface-2); color: var(--text-muted); }

/* --- Agent selector ------------------------------------------------------ */
.agent-selector { display: flex; align-items: center; gap: var(--sp-2); }
.agent-selector select { min-width: 180px; }

/* --- Instruction / MCP blocks -------------------------------------------- */
.instr-file { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--sp-4); overflow: hidden; }
.instr-file-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.instr-file-name { font-weight: 600; font-family: ui-monospace, monospace; font-size: 13px; }
.instr-file textarea { width: 100%; border: none; padding: var(--sp-3); min-height: 220px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; }
.instr-file textarea:focus { outline: none; }
.file-error { color: var(--danger); font-size: 12px; padding: var(--sp-2) var(--sp-3); }

/* --- Status / Claude CLI ------------------------------------------------- */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: var(--sp-2) var(--sp-4); font-size: 14px; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }

/* --- Loading / errors ---------------------------------------------------- */
.loading-center { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); padding: var(--sp-6); color: var(--text-muted); }
.empty-hint { color: var(--text-subtle); font-size: 13px; padding: var(--sp-4); text-align: center; }
.inline-error { background: var(--danger-soft); border: 1px solid #f6cfcf; color: var(--danger); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: var(--sp-3); }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center; padding: var(--sp-4); z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: #1e293b; color: #fff; padding: 11px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 13px; display: flex; align-items: flex-start; gap: var(--sp-2); animation: toast-in 0.18s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast-close { margin-left: auto; opacity: 0.7; color: inherit; background: none; line-height: 1; }
.toast-close:hover { opacity: 1; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--radius-sm); color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.hidden { display: none !important; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; }
  .tabs { flex-direction: row; flex-wrap: wrap; position: static; }
  .kv { grid-template-columns: 1fr; gap: 2px var(--sp-4); }
  .kv dt { margin-top: var(--sp-2); }
}
