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

:root {
  /* Brand */
  --purple:        #7c3aed;
  --purple-dark:   #5b21b6;
  --purple-light:  #ede9fe;
  --purple-mid:    #8b5cf6;

  /* Status */
  --green:         #16a34a;
  --green-bg:      #dcfce7;
  --amber:         #d97706;
  --amber-bg:      #fef3c7;
  --red:           #dc2626;
  --red-bg:        #fee2e2;
  --blue:          #2563eb;
  --blue-bg:       #eff6ff;

  /* Neutrals */
  --grey-50:       #f8fafc;
  --grey-100:      #f1f5f9;
  --grey-200:      #e2e8f0;
  --grey-300:      #cbd5e1;
  --grey-400:      #94a3b8;
  --grey-500:      #64748b;
  --grey-600:      #475569;
  --grey-700:      #334155;
  --grey-800:      #1e293b;
  --grey-900:      #0f172a;

  /* Sidebar */
  --sidebar-bg:    #0f172a;
  --sidebar-w:     220px;

  /* Layout */
  --radius:        10px;
  --radius-lg:     14px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:     0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--grey-800);
  background: var(--grey-50);
}

/* ── Login Screen ────────────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--grey-900) 0%, #1e1b4b 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .logo-icon {
  width: 52px;
  height: 52px;
  background: var(--purple);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: .75rem;
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--grey-900);
}

.login-logo p {
  font-size: .85rem;
  color: var(--grey-500);
  margin-top: .2rem;
}

.login-card .field {
  margin-bottom: 1rem;
}

.login-card label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--grey-600);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.login-card input {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}

.login-card input:focus { border-color: var(--purple); }

.login-error {
  color: var(--red);
  font-size: .85rem;
  margin-bottom: .75rem;
  min-height: 1.2em;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, background .15s, transform .1s;
  text-decoration: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--purple);
  color: white;
  width: 100%;
  justify-content: center;
  padding: .75rem;
  font-size: 1rem;
}
.btn-primary:hover:not(:disabled) { background: var(--purple-dark); }

.btn-secondary {
  background: var(--grey-100);
  color: var(--grey-700);
}
.btn-secondary:hover:not(:disabled) { background: var(--grey-200); }

.btn-success {
  background: var(--green);
  color: white;
}
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: #fecaca; }

.btn-ghost {
  background: transparent;
  color: var(--grey-500);
  padding: .4rem .7rem;
}
.btn-ghost:hover:not(:disabled) { background: var(--grey-100); color: var(--grey-700); }

.btn-sm {
  padding: .35rem .75rem;
  font-size: .82rem;
}

/* ── App Shell ───────────────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 1.4rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .7rem;
  text-decoration: none;
}

.sidebar-logo .logo-icon {
  width: 34px;
  height: 34px;
  background: var(--purple);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-size: .95rem;
  font-weight: 700;
  color: white;
  line-height: 1.1;
}

.sidebar-logo .logo-sub {
  font-size: .7rem;
  color: rgba(255,255,255,.4);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0 .6rem;
  margin-bottom: .25rem;
}

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  color: rgba(255,255,255,.3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .6rem .6rem .3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: 8px;
  text-decoration: none;
  color: rgba(255,255,255,.55);
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}

.nav-link:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.85);
}

.nav-link.active {
  background: var(--purple);
  color: white;
}

.nav-link .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  font-size: .65rem;
  font-weight: 700;
  color: rgba(255,255,255,.4);
  margin-left: auto;
  flex-shrink: 0;
}

.nav-link.active .nav-step {
  background: rgba(255,255,255,.25);
  color: white;
}

.sidebar-footer {
  padding: .75rem .6rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar-footer .nav-link {
  font-size: .82rem;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: white;
  border-bottom: 1px solid var(--grey-200);
  padding: 1.2rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--grey-900);
}

.page-header p {
  font-size: .85rem;
  color: var(--grey-500);
  margin-top: .1rem;
}

.page-body {
  padding: 2rem;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--grey-200);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ── Status Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-pending  { background: var(--grey-100);  color: var(--grey-600); }
.badge-approved { background: var(--green-bg);  color: var(--green); }
.badge-rejected { background: var(--red-bg);    color: var(--red); }
.badge-draft    { background: var(--amber-bg);  color: var(--amber); }
.badge-final    { background: var(--green-bg);  color: var(--green); }
.badge-queued   { background: var(--grey-100);  color: var(--grey-600); }
.badge-generating { background: var(--blue-bg); color: var(--blue); }
.badge-done     { background: var(--green-bg);  color: var(--green); }
.badge-failed   { background: var(--red-bg);    color: var(--red); }

/* ── Form Elements ───────────────────────────────────────────────────────── */
.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--grey-600);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  background: white;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--purple);
}

.field textarea {
  resize: vertical;
  min-height: 90px;
}

.field-hint {
  font-size: .78rem;
  color: var(--grey-400);
  margin-top: .3rem;
}

.char-counter {
  font-size: .75rem;
  color: var(--grey-400);
  text-align: right;
  margin-top: .2rem;
}
.char-counter.over { color: var(--red); font-weight: 600; }

/* ── Settings Page ───────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  gap: 1.5rem;
  max-width: 640px;
}

.settings-section h2 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--grey-700);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1.5px solid var(--grey-100);
}

.api-key-field {
  position: relative;
}

.api-key-field input {
  padding-right: 4rem;
}

.api-key-toggle {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--grey-400);
  cursor: pointer;
  font-size: .8rem;
  padding: .25rem .4rem;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: slideInRight .2s ease;
  max-width: 320px;
}

.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }
.toast-info    { background: var(--purple); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(1rem); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--grey-400);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--grey-500);
  margin-bottom: .4rem;
}

.empty-state p {
  font-size: .875rem;
}

/* ── Loading Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner-dark {
  border-color: var(--grey-200);
  border-top-color: var(--purple);
}

@keyframes spin { to { transform: rotate(360deg); } }

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

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex   { display: flex; }
.items-center { align-items: center; }
.gap-2  { gap: .5rem; }
.gap-3  { gap: .75rem; }
.ml-auto { margin-left: auto; }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.text-muted { color: var(--grey-400); }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.w-full { width: 100%; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  #sidebar {
    display: none;
  }

  #main {
    margin-left: 0;
  }

  .page-body {
    padding: 1rem;
  }

  .page-header {
    padding: 1rem;
  }
}
