@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg:             #f3f4f6;
  --surface:        #ffffff;
  --border:         #e5e7eb;
  --border-light:   #f3f4f6;
  --text:           #111827;
  --muted:          #6b7280;
  --subtle:         #9ca3af;
  --primary:        #f6821f;
  --primary-hover:  #e5731a;
  --primary-light:  #fff7ed;
  --danger:         #dc2626;
  --danger-hover:   #b91c1c;
  --danger-light:   #fef2f2;
  --success:        #16a34a;
  --success-light:  #f0fdf4;
  --success-border: #86efac;
  --warning:        #d97706;
  --warning-light:  #fffbeb;
  --nav-bg:         #1d2129;
  --nav-text:       #d1d5db;
  --nav-hover:      #ffffff;
  --nav-active:     #f6821f;
  --shadow-sm:      0 1px 2px rgba(0,0,0,0.05);
  --shadow:         0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:      0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --radius:         6px;
  --radius-lg:      8px;
  --font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:           'SF Mono', 'Consolas', 'Monaco', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ─────────────────────────────────────────── */
nav {
  background: var(--nav-bg);
  display: flex;
  align-items: stretch;
  padding: 0 1.5rem;
  height: 52px;
  gap: 0;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav .brand {
  display: flex;
  align-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  letter-spacing: -0.01em;
  padding-right: 1.5rem;
  margin-right: 0.5rem;
  border-right: 1px solid rgba(255,255,255,0.1);
}

nav .brand span { color: var(--primary); }

nav ul {
  display: flex;
  list-style: none;
  align-items: stretch;
  gap: 0;
}

nav ul li { display: flex; align-items: stretch; }

nav ul a {
  display: flex;
  align-items: center;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0 1rem;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

nav ul a:hover { color: var(--nav-hover); }
nav ul a.active { color: #fff; border-bottom-color: var(--primary); }

nav .nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
}

nav .nav-right .nav-user {
  color: var(--nav-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

nav .nav-right .nav-user::before {
  content: '';
  display: inline-block;
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23d1d5db'%3E%3Cpath d='M12 12c2.7 0 4.8-2.1 4.8-4.8S14.7 2.4 12 2.4 7.2 4.5 7.2 7.2 9.3 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8v2.4h19.2v-2.4c0-3.2-6.4-4.8-9.6-4.8z'/%3E%3C/svg%3E");
  background-size: 18px;
  background-repeat: no-repeat;
  background-position: center;
}

nav .nav-right a {
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

nav .nav-right a:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* ── Page shell ─────────────────────────────────────────── */
main { max-width: 1200px; margin: 2rem auto; padding: 0 1.5rem; }

/* ── Login page ─────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--nav-bg);
  letter-spacing: -0.02em;
}
.login-logo span { color: var(--primary); }

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.login-box h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text);
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.card-body { padding: 1.25rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid .span-2 { grid-column: span 2; }

form { display: flex; flex-direction: column; gap: 1rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
}

label small {
  font-weight: 400;
  color: var(--muted);
}

input[type=text],
input[type=password],
input[type=number],
input[type=date],
input[type=email],
textarea,
select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(246,130,31,0.12);
}

input::placeholder, textarea::placeholder { color: var(--subtle); }

textarea { min-height: 5rem; resize: vertical; }

/* ── Buttons ─────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  background: var(--primary);
  color: #fff;
}

button:hover, .btn:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: #d1d5db;
}

.btn-danger, button.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
}

.btn-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

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

.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--subtle); }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.alert-success {
  background: var(--success-light);
  border-color: var(--success-border);
  color: var(--success);
}

.alert-error {
  background: var(--danger-light);
  border-color: #fca5a5;
  color: var(--danger);
}

.alert-warning {
  background: var(--warning-light);
  border-color: #fcd34d;
  color: var(--warning);
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

th {
  background: #f9fafb;
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.875rem;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

td a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

td a:hover { text-decoration: underline; }

.table-actions { display: flex; gap: 0.4rem; align-items: center; }

/* ── Detail table ─────────────────────────────────────────── */
.detail-table { max-width: 640px; }
.detail-table th {
  width: 170px;
  background: #f9fafb;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.detail-table td { font-family: var(--mono); font-size: 0.82rem; }
.detail-table td.plain { font-family: var(--font); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-green  { background: #dcfce7; color: #16a34a; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-blue   { background: #dbeafe; color: #2563eb; }
.badge-orange { background: #fff7ed; color: #ea580c; }

.badge::before { content: '●'; font-size: 0.6rem; }

/* ── Stat cards ──────────────────────────────────────────── */
.stats { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  min-width: 150px;
  box-shadow: var(--shadow-sm);
}

.stat-num {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 0.3rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Terminal output ─────────────────────────────────────── */
.output {
  background: #0f1117;
  color: #e2e8f0;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.7;
  white-space: pre;
  max-height: 75vh;
  max-width: 100%;
  width: 100%;
  border: 1px solid #1e293b;
  box-sizing: border-box;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar select { width: auto; }

/* ── Log layout ──────────────────────────────────────────── */
.log-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; }
.log-layout .log-content { min-width: 0; }

.log-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  height: fit-content;
}

.log-list h3 {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.log-list ul { list-style: none; }
.log-list ul li { padding: 0.1rem 0; }

.log-list ul a {
  display: block;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.1s;
}

.log-list ul a:hover { background: var(--bg); }
.log-list ul a.active { background: var(--primary); color: #fff; }

.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.log-toolbar form { flex-direction: row; gap: 0.5rem; }

/* ── Token display ───────────────────────────────────────── */
.token-display {
  display: block;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
  cursor: pointer;
  color: var(--text);
}

.token-display:hover { background: var(--bg); }

/* ── Actions row ─────────────────────────────────────────── */
.actions { display: flex; gap: 0.75rem; margin: 1.25rem 0; flex-wrap: wrap; }

/* ── Section heading ─────────────────────────────────────── */
h1 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; letter-spacing: -0.02em; }
h2 { font-size: 0.9rem; font-weight: 600; margin: 1.5rem 0 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

small { font-weight: 400; color: var(--muted); }
p { margin-bottom: 0.75rem; font-size: 0.875rem; }
code { font-family: var(--mono); background: #f1f5f9; padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.85em; }

/* ── Server switcher ─────────────────────────────────────── */
.server-switcher { display: flex; align-items: center; gap: 0.5rem; }
.server-switcher select { width: auto; font-weight: 500; }

/* ── Divider ─────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
}

.empty-state p { margin-bottom: 1rem; }
