/* ─── Reset & Base ───────────────────────────────────────────────────────── */

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

:root {
  --gray-1: #fcfcfc;
  --gray-2: #f9f9f9;
  --gray-3: #f0f0f0;
  --gray-4: #e8e8e8;
  --gray-5: #e0e0e0;
  --gray-6: #d9d9d9;
  --gray-7: #cecece;
  --gray-8: #bbbbbb;
  --gray-9: #8d8d8d;
  --gray-10: #838383;
  --gray-11: #646464;
  --gray-12: #202020;

  --blue-9: #0090ff;
  --blue-10: #0588f0;
  --blue-11: #0d74ce;
  
  --red-9: #e5484d;
  --red-10: #dc3e42;
  --red-11: #ce2c31;
  
  --green-9: #30a46c;
  --green-10: #299764;
  --green-11: #18794e;
  
  --amber-9: #ffb224;
  --amber-10: #ffa01c;
  --amber-11: #ad5700;

  --radius: 6px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-12);
  background: var(--gray-2);
  -webkit-font-smoothing: antialiased;
}

/* ─── Auth Layout ────────────────────────────────────────────────────────── */

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: white;
  border: 1px solid var(--gray-6);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 32px;
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--gray-12);
  margin-bottom: 8px;
}

.auth-header p {
  font-size: 14px;
  color: var(--gray-11);
}

/* ─── App Layout ─────────────────────────────────────────────────────────── */

.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid var(--gray-6);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-6);
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-12);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
}

.nav-item {
  display: block;
  padding: 8px 12px;
  color: var(--gray-11);
  text-decoration: none;
  border-radius: var(--radius);
  margin-bottom: 4px;
  font-size: 14px;
  transition: all 0.15s;
}

.nav-item:hover {
  background: var(--gray-3);
  color: var(--gray-12);
}

.nav-item.active {
  background: var(--gray-4);
  color: var(--gray-12);
  font-weight: 500;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--gray-6);
}

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

/* ─── Page Header ────────────────────────────────────────────────────────── */

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 600;
  color: var(--gray-12);
  margin-bottom: 8px;
}

.page-header p {
  font-size: 14px;
  color: var(--gray-11);
}

/* ─── Card ───────────────────────────────────────────────────────────────── */

.card {
  background: white;
  border: 1px solid var(--gray-6);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
}

.card-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-5);
}

.card-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-12);
}

.card-header p {
  font-size: 13px;
  color: var(--gray-11);
  margin-top: 4px;
}

/* ─── Form Elements ──────────────────────────────────────────────────────── */

.form-field {
  margin-bottom: 20px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-12);
  margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--gray-12);
  background: white;
  border: 1px solid var(--gray-7);
  border-radius: var(--radius);
  transition: all 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--blue-9);
  box-shadow: 0 0 0 3px rgba(0, 144, 255, 0.1);
}

input::placeholder {
  color: var(--gray-9);
}

.form-helper {
  font-size: 12px;
  color: var(--gray-11);
  margin-top: 6px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gray-12);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--gray-11);
}

.btn-secondary {
  background: var(--gray-3);
  color: var(--gray-12);
  border: 1px solid var(--gray-7);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-4);
}

.btn-danger {
  background: var(--red-9);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--red-10);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* ─── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-top: 16px;
  border: 1px solid;
}

.alert-success {
  background: #e6f7ed;
  border-color: var(--green-9);
  color: var(--green-11);
}

.alert-error {
  background: #fef1f1;
  border-color: var(--red-9);
  color: var(--red-11);
}

.alert-warning {
  background: #fef9ed;
  border-color: var(--amber-9);
  color: var(--amber-11);
}

.alert-info {
  background: #f0f9ff;
  border-color: var(--blue-9);
  color: var(--blue-11);
}

/* ─── Status Badge ───────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  border: 1px solid;
}

.badge-success {
  background: #e6f7ed;
  border-color: var(--green-9);
  color: var(--green-11);
}

.badge-error {
  background: #fef1f1;
  border-color: var(--red-9);
  color: var(--red-11);
}

.badge-warning {
  background: #fef9ed;
  border-color: var(--amber-9);
  color: var(--amber-11);
}

.badge-neutral {
  background: var(--gray-3);
  border-color: var(--gray-7);
  color: var(--gray-11);
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 8px;
}

.gap-4 {
  gap: 16px;
}

/* ─── Code Block ─────────────────────────────────────────────────────────── */

pre {
  background: var(--gray-2);
  border: 1px solid var(--gray-6);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 13px;
  overflow-x: auto;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
  color: var(--gray-12);
}

code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
  font-size: 13px;
  background: var(--gray-3);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--gray-12);
}

/* ─── Link ───────────────────────────────────────────────────────────────── */

a {
  color: var(--blue-11);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ─── QR Code ────────────────────────────────────────────────────────────── */

.qr-display {
  text-align: center;
  padding: 24px;
  background: var(--gray-2);
  border: 1px solid var(--gray-6);
  border-radius: var(--radius);
  margin-top: 16px;
}

.qr-display img {
  max-width: 300px;
  border-radius: var(--radius);
}

/* ─── Instance List ──────────────────────────────────────────────────────── */

.instance-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instance-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--gray-2);
  border: 1px solid var(--gray-6);
  border-radius: var(--radius);
}

.instance-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.instance-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--gray-12);
}

.instance-actions {
  display: flex;
  gap: 8px;
}

.btn-danger {
  background: var(--red-9);
  color: white;
  border: none;
}

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

.mb-4 {
  margin-bottom: 16px;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--gray-6);
  }

  .main-content {
    padding: 20px;
  }

  .instance-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .instance-actions {
    flex-wrap: wrap;
  }
}

#systemPrompt {
    min-width: 565px;
}