/* ==========================================================================
   Global Reset & Base Styles
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: #faf9f5;
  color: #2d2d2b;
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ==========================================================================
   CSS Variables
   ========================================================================== */

:root {
  /* Core Neutrals */
  --color-dark: #141413;
  --color-light: #faf9f5;
  --color-mid-gray: #b0aea5;
  --color-light-gray: #e8e6dc;

  /* Accent Colors */
  --color-orange: #d97757;
  --color-blue: #6a9bcc;
  --color-green: #788c5d;

  /* Background Colors */
  --bg-primary: var(--color-light);
  --bg-card: rgba(232, 230, 220, 0.8);
  --bg-card-solid: rgba(232, 230, 220, 0.95);
  --bg-input: rgba(250, 249, 245, 0.8);
  --bg-hover: rgba(176, 174, 165, 0.2);
  --bg-accent: rgba(217, 119, 87, 0.15);
  --bg-accent-light: rgba(217, 119, 87, 0.1);
  --bg-accent-strong: rgba(217, 119, 87, 0.25);
  --bg-accent-medium: rgba(217, 119, 87, 0.3);
  --bg-error: rgba(220, 80, 80, 0.15);
  --bg-success: rgba(120, 140, 93, 0.15);
  --bg-blue: rgba(106, 155, 204, 0.15);
  --bg-blue-light: rgba(106, 155, 204, 0.08);
  --bg-blue-medium: rgba(106, 155, 204, 0.2);

  /* Gradient backgrounds */
  --gradient-accent: linear-gradient(135deg, rgba(217, 119, 87, 0.15) 0%, rgba(106, 155, 204, 0.15) 100%);
  --gradient-accent-light: linear-gradient(135deg, rgba(217, 119, 87, 0.1) 0%, rgba(106, 155, 204, 0.08) 100%);

  /* Shadow colors */
  --shadow-accent: rgba(217, 119, 87, 0.4);

  /* Text Colors */
  --text-primary: var(--color-dark);
  --text-secondary: #2d2d2b;
  --text-muted: #6b6a65;
  --text-dimmed: var(--color-mid-gray);
  --text-accent: var(--color-orange);
  --text-error: #c44;
  --text-error-hover: #a33;
  --text-success: var(--color-green);
  --text-highlight: #c7d2fe;

  /* Border Colors */
  --border-subtle: rgba(176, 174, 165, 0.2);
  --border-medium: rgba(176, 174, 165, 0.4);
  --border-input: var(--color-light-gray);
  --border-accent: rgba(217, 119, 87, 0.4);
  --border-accent-strong: rgba(217, 119, 87, 0.5);
  --border-error: rgba(220, 80, 80, 0.4);
  --border-success: rgba(120, 140, 93, 0.4);

  /* Accent Colors (functional) */
  --accent-primary: var(--color-orange);
  --accent-primary-hover: #c4654a;
  --accent-secondary: var(--color-blue);
  --accent-secondary-hover: #5889b8;
  --accent-tertiary: var(--color-green);

  /* Fonts */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'SF Mono', Monaco, monospace;

  /* Font Sizes */
  --text-xs: 0.7rem;
  --text-sm: 0.75rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.75rem;
  --text-4xl: 2rem;

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-2xl: 16px;
  --radius-full: 9999px;

  /* Layout */
  --max-width: 1200px;

  /* Spacing (for reference) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
}

/* ==========================================================================
   Button Components
   ========================================================================== */

/* Base button styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  font-family: var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Primary button - solid orange */
.btn-primary {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

/* Secondary button - outlined/ghost */
.btn-secondary {
  background: var(--bg-accent);
  color: var(--text-accent);
  border-color: var(--border-accent);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-accent-medium);
}

/* Ghost button - minimal */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-subtle);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Danger button - for destructive actions */
.btn-danger {
  background: var(--bg-error);
  color: var(--text-error);
  border-color: var(--border-error);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(220, 80, 80, 0.25);
}

/* Success state for buttons */
.btn.copied,
.btn-success {
  background: var(--bg-success);
  color: var(--color-green);
  border-color: var(--border-success);
}

/* Size variants */
.btn-sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

/* Full-width button modifier */
.btn-block {
  width: 100%;
}

/* ==========================================================================
   Form Components
   ========================================================================== */

.form-group {
  margin-bottom: var(--space-4);
}

.form-group label {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

/* Base input styles - applies to input, textarea, select */
.form-input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="tel"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: var(--text-md);
  font-family: var(--font-sans);
  transition: border-color 0.2s;
}

.form-input:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

/* Form error message */
.form-error {
  background: var(--bg-error);
  border: 1px solid var(--border-error);
  color: var(--text-error);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
}

/* Form success message */
.form-success {
  background: var(--bg-success);
  border: 1px solid var(--border-success);
  color: var(--text-success);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  text-align: center;
}

.form-success h3 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   Card & Container Components
   ========================================================================== */

/* Base card style */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-2xl);
  padding: var(--space-8);
}

.card-solid {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-subtle);
}

/* Auth container - centered card for login/authorize pages */
.auth-container {
  background: var(--bg-card);
  border-radius: var(--radius-2xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
}

/* Auth wrapper - centers the auth container */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: var(--space-8);
}

/* Page container - max-width wrapper */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.container-sm {
  max-width: 700px;
}

.container-xs {
  max-width: 400px;
}

/* Section spacing */
.section {
  margin-bottom: var(--space-6);
}

/* Page header */
.page-header {
  text-align: center;
  margin-bottom: var(--space-8);
}

.page-header h1 {
  font-size: var(--text-4xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.page-header .subtitle {
  color: var(--text-dimmed);
  font-size: var(--text-md);
}

/* Subtitle text */
.subtitle {
  color: var(--text-dimmed);
}

/* Back link */
.back-link {
  display: inline-block;
  margin-bottom: var(--space-6);
  color: var(--text-dimmed);
  font-size: var(--text-base);
  text-decoration: none;
}

.back-link:hover {
  color: var(--text-accent);
}

/* ==========================================================================
   Mobile Responsive - Form & Card
   ========================================================================== */

@media (max-width: 480px) {
  .auth-wrapper {
    padding: var(--space-4);
  }

  .auth-container {
    padding: 1.5rem;
  }

  .card {
    padding: var(--space-6);
  }

  /* Touch-friendly input sizes */
  .form-input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input[type="tel"],
  input[type="search"],
  textarea,
  select {
    min-height: 48px;
  }

  .btn-block {
    min-height: 48px;
  }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

/* Flexbox utilities */
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
}

/* Gap utilities */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Margin utilities */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

/* Padding utilities */
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }

/* Width utilities */
.w-full { width: 100%; }

/* Text utilities */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }

.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-dimmed { color: var(--text-dimmed); }
.text-accent { color: var(--text-accent); }
.text-error { color: var(--text-error); }
.text-success { color: var(--text-success); }

.uppercase {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Label styles */
.label-small {
  font-size: var(--text-xs);
  color: var(--text-dimmed);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--font-medium);
}

/* Hidden utility */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Modal/Overlay Component
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  padding: var(--space-4);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--text-2xl);
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
}

/* Popover variant (smaller, for raw data display etc) */
.popover-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  padding: var(--space-4);
}

.popover-overlay.active {
  opacity: 1;
  visibility: visible;
}

.popover {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.25);
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.popover-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.popover-close {
  background: none;
  border: none;
  font-size: var(--text-xl);
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
  transition: color 0.2s;
}

.popover-close:hover {
  color: var(--text-primary);
}

.popover-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

.popover-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Link Styles
   ========================================================================== */

.link {
  color: var(--text-accent);
  text-decoration: none;
  transition: color 0.2s;
}

.link:hover {
  text-decoration: underline;
}

.link-muted {
  color: var(--text-muted);
}

.link-muted:hover {
  color: var(--text-accent);
}

/* ==========================================================================
   MCP Field Component (for mcp-setup page)
   ========================================================================== */

.mcp-field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.mcp-field-label {
  font-size: var(--text-xs);
  color: var(--text-dimmed);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.mcp-field-label-lg {
  margin-bottom: 0.5rem;
}

/* ==========================================================================
   Password Toggle Button
   ========================================================================== */

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
}

.password-toggle:hover {
  color: var(--text-primary);
}

/* ==========================================================================
   Delete/Danger Button Styles
   ========================================================================== */

.btn-danger-solid {
  background: var(--text-error);
  color: white;
  border: none;
}

.btn-danger-solid:hover:not(:disabled) {
  background: var(--text-error-hover);
}

/* ==========================================================================
   Page Container (shared across all pages)
   ========================================================================== */

.page-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-8);
}

@media (max-width: 640px) {
  .page-container {
    padding: var(--space-4);
  }
}

/* ==========================================================================
   Section Card (shared card styling for page sections)
   ========================================================================== */

.section-card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

@media (max-width: 640px) {
  .section-card {
    padding: var(--space-4);
  }
}

/* ==========================================================================
   Copy Button (shared copy button styling)
   ========================================================================== */

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-accent);
  border: 1px solid var(--border-accent);
  color: var(--text-accent);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.copy-btn:hover {
  background: var(--bg-accent-medium);
}

.copy-btn.copied {
  background: var(--bg-success);
  border-color: var(--border-success);
  color: var(--color-green);
}

/* ==========================================================================
   Utility Color Classes for Table Cells
   ========================================================================== */

.text-blue { color: var(--color-blue); }
.text-green { color: var(--color-green); }
.text-orange { color: var(--color-orange); }

/* ==========================================================================
   Position Utilities
   ========================================================================== */

.relative { position: relative; }
.absolute { position: absolute; }
