/* === Custom Properties === */
:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-success: #16a34a;
  --color-error: #dc2626;
  --color-warning: #ca8a04;
  --color-info: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* === Layout === */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }

nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 0;
  box-shadow: var(--shadow);
}
nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
nav .brand { font-size: 1.25rem; font-weight: 700; color: var(--color-text); }
nav .nav-links { display: flex; align-items: center; gap: 1rem; }
nav .nav-links a { color: var(--color-text-muted); font-size: 0.9rem; }
nav .user-info { display: flex; align-items: center; gap: 0.5rem; }
nav .user-info img { width: 28px; height: 28px; border-radius: 50%; }

main { padding: 2rem 0; }

/* === Grid === */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

/* === Card === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card h3 { margin-bottom: 0.5rem; }
.card .meta { color: var(--color-text-muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
.card .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* === Status Badges === */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-running { background: #dcfce7; color: var(--color-success); }
.badge-stopped { background: #f1f5f9; color: var(--color-text-muted); }
.badge-error   { background: #fee2e2; color: var(--color-error); }
.badge-creating { background: #fef9c3; color: var(--color-warning); }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}
input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-surface);
  color: var(--color-text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* === Alerts === */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success { background: #dcfce7; color: var(--color-success); }
.alert-error   { background: #fee2e2; color: var(--color-error); }
.alert-info    { background: #dbeafe; color: var(--color-info); }

/* === Hero / Landing === */
.hero {
  text-align: center;
  padding: 4rem 1rem;
}
.hero h1 { font-size: 2.5rem; margin-bottom: 0.75rem; }
.hero p { font-size: 1.15rem; color: var(--color-text-muted); margin-bottom: 2rem; max-width: 600px; margin-left: auto; margin-right: auto; }
.hero .auth-buttons { display: flex; gap: 1rem; justify-content: center; }

/* === Dashboard Header === */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.dash-header h1 { font-size: 1.5rem; }

/* === Onboard / Settings Form === */
.form-card {
  max-width: 500px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}
.form-card h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }

/* === Admin Nav Link === */
.nav-admin {
  background: var(--color-primary);
  color: #fff !important;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
}
.nav-admin:hover { background: var(--color-primary-hover); text-decoration: none; }

/* === Admin Layout === */
.admin-nav {
  background: #1e293b;
  border-bottom: none;
  padding: 0.75rem 0;
  box-shadow: var(--shadow);
}
.admin-nav .container { display: flex; align-items: center; justify-content: space-between; }
.admin-nav .brand { font-size: 1.25rem; font-weight: 700; color: #fff; }
.admin-nav .nav-links { display: flex; align-items: center; gap: 1rem; }
.admin-nav .nav-links a { color: #94a3b8; font-size: 0.9rem; }
.admin-nav .nav-links a:hover { color: #fff; text-decoration: none; }
.admin-nav .user-info { display: flex; align-items: center; gap: 0.5rem; color: #e2e8f0; }
.admin-nav .user-info img { width: 28px; height: 28px; border-radius: 50%; }

.admin-container {
  display: flex;
  min-height: calc(100vh - 56px);
}

.admin-sidebar {
  width: 200px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1rem 0;
  flex-shrink: 0;
}
.sidebar-link {
  display: block;
  padding: 0.6rem 1.25rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.sidebar-link:hover { background: var(--color-bg); color: var(--color-text); text-decoration: none; }
.sidebar-link.active { color: var(--color-primary); background: #eff6ff; border-right: 3px solid var(--color-primary); }

.admin-main {
  flex: 1;
  padding: 1.5rem 2rem;
}
.admin-main h1 { font-size: 1.5rem; margin-bottom: 1.25rem; }
.admin-main h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }

/* === Admin Stats === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-card h3 { font-size: 0.8rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-value.running { color: var(--color-success); }
.stat-value.stopped { color: var(--color-text-muted); }
.stat-value.error { color: var(--color-error); }
.stat-sub { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; }

/* === Admin Table === */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-table th, .admin-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--color-border);
}
.admin-table th {
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f8fafc; }

/* === Admin Toolbar === */
.admin-toolbar {
  margin-bottom: 1rem;
}
.admin-toolbar input[type="search"] {
  max-width: 320px;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

/* === Admin Filter Tabs === */
.filter-tabs { display: flex; gap: 0.25rem; }
.tab {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  cursor: pointer;
}
.tab:hover { background: var(--color-bg); text-decoration: none; }
.tab.active { background: var(--color-primary); color: #fff; }

/* === Admin Detail Card === */
.detail-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.detail-row { padding: 0.4rem 0; font-size: 0.9rem; }
.detail-row strong { color: var(--color-text-muted); min-width: 120px; display: inline-block; }
.detail-actions { margin-top: 1rem; display: flex; gap: 0.5rem; }

/* === Settings Page (wide layout + tabs) === */
.settings-wide {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}
.settings-wide h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }
.settings-wide h2 { margin-bottom: 1rem; font-size: 1.2rem; }

.finger-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1.5rem;
}
.finger-tab {
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.finger-tab:hover { color: var(--color-text); }
.finger-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

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

.finger-panel .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

textarea.system-prompt {
  width: 100%;
  min-height: 120px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
}
textarea.system-prompt:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.settings-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}
.tools-grid label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
}
.tools-grid input[type="checkbox"] { width: auto; }

/* === Responsive === */
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.8rem; }
  .hero .auth-buttons { flex-direction: column; align-items: center; }
  .dash-header { flex-direction: column; gap: 0.75rem; align-items: flex-start; }
  .admin-container { flex-direction: column; }
  .admin-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); display: flex; padding: 0.5rem; gap: 0.25rem; overflow-x: auto; }
  .sidebar-link { padding: 0.4rem 0.75rem; white-space: nowrap; }
  .sidebar-link.active { border-right: none; border-bottom: 3px solid var(--color-primary); }
  .admin-main { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
