/* Gridmaker Suite - Main Interface Styles */

/* CSS Variables for consistent theming */
:root {
  --primary: #4a9eff;
  --primary-dark: #3182ce;
  --bg: #0b0e14;
  --bg-light: #1a1d24;
  --panel: #151922;
  --panel-light: #1f2329;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-dim: #a0aec0;
  --accent: #38b2ac;
  --success: #48bb78;
  --warning: #ed8936;
  --error: #f56565;
}

/* Global Styles */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #0f1320, #0b0e14);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden; /* Prevent page scroll */
}

/* Hide app shell until authenticated */
.hidden-until-auth { display: none; }

/* App shell wraps the original body children; ensure it fills viewport and uses column layout */
.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Auth Gate Styles */
.auth-gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(72, 187, 120, 0.08), transparent 60%),
              radial-gradient(1200px 600px at 50% 110%, rgba(49, 130, 206, 0.08), transparent 60%),
              var(--bg);
  z-index: 1000;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 24px;
  width: min(420px, 92vw);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.auth-card h2 {
  margin: 0 0 6px 0;
  font-size: 18px;
}

.auth-subtitle {
  margin: 0 0 16px 0;
  color: var(--text-dim);
  font-size: 12px;
}

.auth-error {
  display: none;
  margin-top: 12px;
  color: var(--error);
  font-size: 12px;
}

.signout-btn {
  position: absolute;
  right: 12px;
  top: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.signout-btn:hover {
  background: var(--panel-light);
  color: var(--text);
}

/* Make layout height robust: header + tabs natural height, content fills remainder */
body {
  display: flex;
  flex-direction: column;
}

/* App Header */
.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.app-header .subtitle {
  margin: 2px 0 0 0;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
}

/* Tab Navigation */
.tab-navigation {
  display: flex;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  padding: 0;
  margin: 0;
  justify-content: center;
}

.tab-button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 100px;
  position: relative;
  border-bottom: 2px solid transparent;
}

.tab-button:hover {
  background: var(--panel);
  color: var(--text);
  border-bottom-color: var(--primary);
}

.tab-button.active {
  background: var(--panel-light);
  color: var(--text);
  border-bottom-color: var(--primary);
}

.tab-button.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--primary);
}

.tab-icon {
  font-size: 16px;
  display: block;
}

.tab-label {
  font-weight: 600;
  font-size: 11px;
}

.tab-desc {
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 400;
}

.tab-button:hover .tab-desc,
.tab-button.active .tab-desc {
  color: var(--primary);
}

/* System Container */
.system-container {
  flex: 1;
  min-height: 0; /* allow children to size within viewport */
  position: relative;
  overflow: hidden;
}

.system-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.system-panel.active {
  opacity: 1;
  visibility: visible;
}

.system-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--bg);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.system-frame.loaded {
  opacity: 1;
}

/* System Switching Animation */
.system-switching .system-panel {
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

/* Loading States */
.system-frame::before {
  content: 'Loading system...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 14px;
  z-index: 1;
}

.system-frame.loaded::before {
  display: none;
}

/* Keyboard Shortcuts Indicator */
.tab-button::before {
  content: attr(data-shortcut);
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--border);
  color: var(--text-dim);
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tab-button:hover::before {
  opacity: 1;
}

/* Add keyboard shortcut indicators */
.tab-button[data-system="bezel-builder"]::before {
  content: "Ctrl+1";
}

.tab-button[data-system="modular-bezels"]::before {
  content: "Ctrl+2";
}

.tab-button[data-system="frame-builder"]::before {
  content: "Ctrl+3";
}

.tab-button[data-system="ai-ui"]::before {
  content: "Ctrl+4";
}

/* Responsive Design */
@media (max-width: 768px) {
  .tab-navigation {
    flex-direction: column;
    align-items: stretch;
  }
  
  .tab-button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-width: auto;
    padding: 12px 20px;
    border-bottom: none;
    border-left: 3px solid transparent;
  }
  
  .tab-button:hover,
  .tab-button.active {
    border-left-color: var(--primary);
    border-bottom-color: transparent;
  }
  
  .tab-button.active::after {
    left: -1px;
    top: 50%;
    transform: translateY(-50%);
  }
  
  .system-container {
    height: calc(100vh - 140px);
  }
  
  .app-header h1 {
    font-size: 16px;
  }
}

/* Focus Management */
.tab-button:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --border: #4a5568;
    --text-dim: #cbd5e0;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .tab-button,
  .system-panel,
  .system-frame {
    transition: none;
  }
}
