/* Tapestry Control Plane -- Geist-inspired design tokens */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --surface-1: rgba(0,0,0,0.02);
  --surface-2: rgba(0,0,0,0.04);
  --surface-3: rgba(0,0,0,0.06);
  --border: #e4e4e7;
  --border-hover: #d4d4d8;
  --ring: 0 0 0 2px rgba(99,102,241,0.2);
  --text-1: #09090b;
  --text-2: #18181b;
  --text-3: #52525b;
  --text-4: #71717a;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-bg: rgba(99,102,241,0.08);
  --accent-bg-hover: rgba(99,102,241,0.12);

  --status-ok: #16a34a;
  --status-warn: #d97706;
  --status-error: #dc2626;
  --status-info: #6366f1;

  --green: #16a34a;
  --amber: #d97706;
  --pink: #db2777;
  --cyan: #0891b2;
  --purple: #7c3aed;
  --red: #dc2626;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);

  --font-sans: 'Geist', 'Inter', -apple-system, system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'Berkeley Mono', 'JetBrains Mono', monospace;

  --sidebar-w: 220px;
  --sidebar-w-collapsed: 48px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-1);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 13px;
  line-height: 1.5;
}

/* -- Layout -- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1px 1fr;
  height: 100vh;
  transition: grid-template-columns 0.2s ease;
}
.layout.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 0px 1fr; }

#app {
  overflow: hidden;
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
}
#app::-webkit-scrollbar { width: 6px; }
#app::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 3px; }

/* -- Sidebar -- */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.sidebar-logo {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}
.collapsed .sidebar-logo { display: none; }
.sidebar-collapse-btn {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-4); border-radius: var(--radius-sm); height: auto;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-collapse-btn:hover { background: var(--surface-2); color: var(--text-2); }

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: color 0.1s;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { color: var(--text-1); }
.nav-item.active { color: var(--text-1); font-weight: 500; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-item svg { flex-shrink: 0; }
.collapsed .nav-label { display: none; }
.collapsed .nav-item { justify-content: center; padding: 5px 0; }
.collapsed .nav-item svg { margin: 0; }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.collapsed .sidebar-footer { padding: 10px 6px; }

/* Sidebar resize handle */
.sidebar-resize-handle {
  width: 1px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 21;
  margin: 0;
  transition: background 0.15s, width 0.1s;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle:active { width: 3px; background: #0070f3; opacity: 0.6; }
.collapsed .sidebar-resize-handle { display: none; }

/* Owner selector in sidebar */
.owner-select {
  position: relative;
}
.owner-trigger {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 5px 8px; cursor: pointer; font-size: 12px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-2);
  justify-content: space-between; height: 30px;
}
.owner-trigger:hover { border-color: var(--border-hover); }
.collapsed .owner-trigger .owner-label { display: none; }
.owner-popover {
  position: absolute; bottom: calc(100% + 4px); left: 0; width: 260px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); z-index: 100; display: none; overflow: hidden;
}
.owner-popover.open { display: block; }
.owner-search {
  width: 100%; border: none; border-bottom: 1px solid var(--border);
  background: transparent; padding: 8px 12px; font-size: 12px;
  outline: none; color: var(--text-1); font-family: var(--font-sans);
}
.owner-search:focus { box-shadow: none; border-color: var(--border); }
.owner-list { max-height: 240px; overflow-y: auto; padding: 4px; }
.owner-list::-webkit-scrollbar { width: 4px; }
.owner-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 2px; }
.owner-item {
  padding: 6px 10px; margin: 1px 0; font-size: 12px; cursor: pointer; border-radius: 3px;
  display: flex; align-items: center; justify-content: space-between; color: var(--text-2);
}
.owner-item:hover { background: var(--surface-2); color: var(--text-1); }
.owner-item.selected { color: var(--accent); font-weight: 500; }
.owner-item .oi-meta { color: var(--text-4); font-size: 10px; font-family: var(--mono); }

/* -- Base components -- */
select, input[type="text"], input[type="password"], textarea {
  font-family: var(--font-sans); font-size: 13px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-1); padding: 6px 10px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input:focus, textarea:focus { border-color: var(--text-4); box-shadow: 0 0 0 1px var(--text-4); }

button {
  font-family: var(--font-sans); font-size: 13px; height: 32px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text-2); cursor: pointer;
  font-weight: 500; white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s; outline: none;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--surface-2); color: var(--text-1); }
button:focus-visible { box-shadow: var(--ring); }
button.btn-primary { background: var(--text-1); border-color: var(--text-1); color: #fff; }
button.btn-primary:hover { background: #27272a; }
button.btn-secondary { background: var(--surface-1); border-color: var(--border); }
button.btn-error { background: #fef2f2; border-color: #fecaca; color: var(--red); }
button.active { color: var(--text-1); font-weight: 600; border-color: var(--border-hover); }
button.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
button.btn-ghost { border: none; background: none; }
button.btn-ghost:hover { background: var(--surface-2); }

/* -- Page layout -- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; min-height: 48px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); background: var(--bg);
  z-index: 5;
}
.page-title { font-size: 16px; font-weight: 600; color: var(--text-1); }
.page-actions { display: flex; gap: 8px; align-items: center; }

.page-body { padding: 20px 24px 80px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--bg);
}
.stat-value { font-size: 20px; font-weight: 600; color: var(--text-1); font-family: var(--font-mono); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-4); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-sub { font-size: 11px; color: var(--text-3); margin-top: 4px; }

/* -- Tabs -- */
.tab-bar {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  background: var(--bg); padding: 0 24px; flex-shrink: 0;
  z-index: 4;
}
.tab-btn {
  padding: 10px 16px; border: none; background: none;
  font-size: 12px; font-weight: 500; color: var(--text-4); cursor: pointer;
  border-bottom: 2px solid transparent; border-radius: 0; height: auto;
  transition: color 0.1s;
}
.tab-btn:hover { color: var(--text-2); background: none; }
.tab-btn.active { color: var(--text-1); border-bottom-color: var(--text-1); font-weight: 500; }

/* -- Tables -- */
.table-striped { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-striped th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-4); font-weight: 500; text-align: left;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
}
.table-striped td {
  padding: 6px 12px; font-size: 12px; border-bottom: 1px solid var(--border);
  color: var(--text-2); vertical-align: top;
}
.table-striped tbody tr:hover { background: var(--surface-1); }
.table-striped tbody tr:nth-child(even) { background: var(--bg-subtle); }
.table-striped tbody tr:nth-child(even):hover { background: var(--surface-1); }

/* -- Badges -- */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  font-size: 11px; font-weight: 500; border-radius: 9999px;
  background: var(--surface-2); color: var(--text-3);
  white-space: nowrap;
}
.badge-ok { background: #f0fdf4; color: var(--green); }
.badge-warn { background: #fffbeb; color: var(--amber); }
.badge-error { background: #fef2f2; color: var(--red); }
.badge-info { background: #eef2ff; color: var(--accent); }

/* Status dot */
.status-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}

/* -- Empty state -- */
.empty-state {
  padding: 40px 20px; text-align: center; color: var(--text-4); font-size: 13px;
}

/* -- Spinner -- */
.spinner {
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -- Toast -- */
#toast-container {
  position: fixed; bottom: 16px; right: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 12px;
  box-shadow: var(--shadow-md); animation: slideIn 0.2s ease;
}
.toast-info { background: #eef2ff; color: var(--accent); border: 1px solid #c7d2fe; }
.toast-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.toast-ok { background: #f0fdf4; color: var(--green); border: 1px solid #bbf7d0; }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } }

/* -- Card groups (Vercel-style grouped items with line separators) -- */
.card-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  overflow: hidden;
}
.card-group-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card-group-item:last-child { border-bottom: none; }

.card-group-row {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  overflow: hidden;
}
.card-group-row > * {
  flex: 1;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
}
.card-group-row > *:last-child { border-right: none; }

/* -- Mono text -- */
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-4); }

/* -- Graph Explorer -- */
.graph-container { position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.graph-canvas { flex: 1; min-height: 0; background: var(--bg); }
.graph-toolbar {
  display: flex; align-items: center; gap: 4px; padding: 4px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg); flex-shrink: 0;
}
.graph-panel {
  width: 380px; border-left: 1px solid var(--border); overflow-y: auto;
  background: var(--bg); flex-shrink: 0; display: flex; flex-direction: column;
  transition: width 0.15s ease; z-index: 10; position: relative;
}
.graph-panel[data-state="closed"] { width: 0; overflow: hidden; border: none; }
.graph-panel-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); min-height: 44px;
}
.graph-loading {
  position: absolute; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,0.8); z-index: 8;
}
.graph-loading.active { display: flex; }
.graph-tab-content { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* -- Auth UI -- */
.auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}
.auth-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
}
.auth-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.auth-email {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.collapsed .auth-info { display: none; }
.collapsed .auth-logout { display: none; }
.auth-logout {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text-4);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.auth-logout:hover { background: var(--surface-2); color: var(--text-2); }
.auth-signin {
  display: flex;
  justify-content: center;
}

/* -- Auth loader -- */
.auth-loader-content {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* -- Auth gate (standalone login page) -- */
.auth-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.auth-gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 56px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 360px;
}
.auth-gate-icon {
  color: var(--text-4);
  margin-bottom: 20px;
}
.auth-gate-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: -0.03em;
  line-height: 1;
}
.auth-gate-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 6px;
}
.auth-gate-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}
#auth-gate-btn {
  display: flex;
  justify-content: center;
  min-height: 40px;
}
.auth-gate-footer {
  font-size: 11px;
  color: var(--text-4);
  margin-top: 20px;
}
.auth-gate-brand {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  width: 100%;
  display: flex;
  justify-content: center;
}
.auth-gate-doss-logo {
  height: 16px;
}
