/* ========================================
   SHARED CSS - Multi-AI Suite
   Common styles, CSS variables, topbar, drawer, buttons, cards
   ======================================== */

/* ========== CSS Variables - Light Theme ========== */
:root {
  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Background */
  --bg: #fff;
  --bg-secondary: #fafafa;
  --bg-tertiary: #f6f6f6;

  /* Text */
  --text: #333;
  --text-muted: #666;

  /* Borders */
  --border: #ddd;
  --border-light: #eee;

  /* Cards */
  --card-bg: #fff;
  --card-border: #ddd;

  /* Inputs */
  --input-bg: #fff;
  --input-border: #ddd;

  /* Buttons */
  --btn-bg: #fff;
  --btn-hover: #f6f6f6;

  /* Pre blocks */
  --pre-bg: #fafafa;
  --pre-border: #eee;

  /* Pills */
  --pill-bg: #fafafa;

  /* Status colors */
  --danger: #c44;
  --danger-bg: #fff6f6;
  --danger-border: #f3b1b1;
  --success: #2e7d32;
  --success-bg: #e8f5e9;
  --success-border: #4caf50;
  --warning: #f57c00;
  --warning-bg: #fff3cd;
  --warning-border: #ffc107;
  --info: #1976d2;
  --info-bg: #f0f7ff;
  --info-border: #64b5f6;

  /* Accent */
  --accent: #4a7c4a;
  --accent-light: #6a9c6a;
  --accent-bg: #e8f4e8;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* ========== CSS Variables - Dark Theme ========== */
[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;

  --text: #e4e4e4;
  --text-muted: #a0a0a0;

  --border: #3a3a5c;
  --border-light: #2a2a4c;

  --card-bg: #16213e;
  --card-border: #3a3a5c;

  --input-bg: #0f3460;
  --input-border: #3a3a5c;

  --btn-bg: #16213e;
  --btn-hover: #0f3460;

  --pre-bg: #0f3460;
  --pre-border: #3a3a5c;

  --pill-bg: #0f3460;

  --danger-bg: #3d1f1f;
  --danger-border: #8b3a3a;
  --success-bg: #1a3d1a;
  --success-border: #2e7d32;
  --warning-bg: #3d3a1a;
  --warning-border: #8b7a2a;
  --info-bg: #1a2d3d;
  --info-border: #3a6a8a;

  --accent: #6a9c6a;
  --accent-light: #8abc8a;
  --accent-bg: #2a3a2a;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
}

/* ========== Base Styles ========== */
* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
}

/* ========== Topbar - Minimal Design ========== */
.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
}

.topbar-logo:hover {
  opacity: 0.8;
}

.logo-icon {
  font-size: 24px;
}

.logo-text {
  color: var(--accent);
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ========== Pills / Badges ========== */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  background: var(--pill-bg);
  min-height: 32px;
  gap: 4px;
  transition: all 0.2s ease;
  text-decoration: none;
  color: var(--text);
}

.pill:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.pill.danger {
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

/* ========== Buttons ========== */
button {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

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

button:active {
  transform: scale(0.98);
}

button.small {
  padding: 6px 10px;
  font-size: 12px;
  min-height: 32px;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover {
  background: var(--accent-light);
}

button.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger-border);
  color: #fff;
}

/* Icon button */
.icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ========== Theme Toggle ========== */
.theme-toggle {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ========== Hamburger Menu Button ========== */
/* HAMBURGER-FIRST: Always visible on all screen sizes */
.hamburger-btn {
  display: flex;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--text);
  align-items: center;
  justify-content: center;
}

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

/* Hide desktop-only actions by default - use drawer instead */
.topbar-actions.desktop-only,
.topbar-buttons.desktop-only {
  display: none;
}

/* ========== Drawer Menu ========== */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  backdrop-filter: blur(4px);
}

.drawer-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: -300px;
  bottom: 0;
  width: 300px;
  background: var(--bg-secondary);
  z-index: 201;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
}

.drawer-overlay.active .drawer {
  right: 0;
}

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

.drawer-header h3 {
  font-size: 16px;
  margin: 0;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-close:hover {
  background: var(--bg-tertiary);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 8px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.drawer-item:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.drawer-item .icon {
  font-size: 20px;
  min-width: 24px;
  text-align: center;
}

.drawer-item.danger {
  color: var(--danger);
}

.drawer-item.danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.drawer-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Sync status in drawer footer */
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
  font-size: 11px;
}

.sync-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.sync-status.fresh .dot { background: #4caf50; }
.sync-status.stale .dot { background: #ffc107; }
.sync-status.old .dot { background: #f44336; }

/* ========== Cards ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.card-header .icon {
  font-size: 20px;
}

/* ========== Grid Layouts ========== */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2, .row2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3, .row3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* ========== Form Elements ========== */
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  min-height: 44px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ========== Collapsible Sections ========== */
.section {
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  min-height: 52px;
  transition: all 0.2s;
  user-select: none;
}

.section-header h3 {
  margin: 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header:hover {
  background: var(--bg-tertiary);
}

.collapse-icon {
  transition: transform 0.2s;
  font-size: 12px;
  padding: 4px;
  min-width: 24px;
  text-align: center;
}

.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.collapsible-content, .section-content {
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-top: none;
  border-radius: 0 0 14px 14px;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.collapsed .collapsible-content,
.collapsed .section-content {
  display: none;
}

/* ========== Utilities ========== */
.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* ========== Pre / Code Blocks ========== */
pre {
  white-space: pre-wrap;
  background: var(--pre-bg);
  border: 1px solid var(--pre-border);
  border-radius: 10px;
  padding: 12px;
  min-height: 60px;
  color: var(--text);
  font-size: 13px;
  overflow-x: auto;
}

/* ========== Focus States (Accessibility) ========== */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.pill:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ========== Container ========== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* ========== Mobile Styles (max-width: 480px) ========== */
@media screen and (max-width: 480px) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* Topbar - mobile adjustments */
  .topbar {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  /* Drawer safe areas */
  .drawer {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    width: 280px;
  }

  /* Grid - single column */
  .grid-2, .grid-3, .grid-4, .row2, .row3 {
    grid-template-columns: 1fr;
  }

  /* Container */
  .container {
    padding: 16px;
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }

  /* Buttons - larger touch targets */
  button {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 15px;
  }

  button.small {
    min-height: 40px;
    padding: 10px 14px;
    font-size: 13px;
  }

  /* Inputs - 16px font to prevent iOS zoom */
  input, select, textarea {
    font-size: 16px;
    padding: 14px 16px;
    min-height: 48px;
  }

  /* Cards */
  .card {
    padding: 14px;
    border-radius: 12px;
  }

  /* Pills */
  .pill {
    padding: 8px 12px;
    font-size: 11px;
  }

  /* Section headers */
  .section-header {
    padding: 14px 16px;
    min-height: 52px;
  }

  /* Pre blocks */
  pre {
    font-size: 12px;
    padding: 10px;
    max-height: 300px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Extra small screens (iPhone SE, etc) */
@media screen and (max-width: 375px) {
  .topbar-logo .logo-text {
    font-size: 16px;
  }

  button {
    padding: 10px 12px;
    font-size: 13px;
  }

  .card {
    padding: 12px;
  }
}

/* Tablet breakpoint */
@media screen and (max-width: 768px) {
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media screen and (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}
