@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-light: #f9f9f9;
  --bg-panel: rgba(255, 255, 255, 0.95);
  --bg-white: #ffffff;
  --primary: #0c2340;
  --primary-light: #1d3d6b;
  --primary-glow: rgba(12, 35, 64, 0.15);
  --secondary: #b8860b;
  --secondary-light: #dfb33e;
  --accent: #27ae60;
  --accent-light: #a8e6cf;
  --warm: #d4a574;
  --warm-light: #f5e6d3;
  --text-main: #2c3e50;
  --text-muted: #7f8c8d;
  --text-dark: #0c2340;
  --border: rgba(0, 0, 0, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.06);
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
}

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

body {
  font-family: 'Noto Sans TC', 'Outfit', sans-serif;
  background-color: var(--bg-light);
  color: var(--text-main);
  background-image:
    linear-gradient(rgba(212, 165, 116, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 165, 116, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Global form elements fix (only in light-theme areas, not dark pages) ── */

.layout-grid input, .layout-grid select, .layout-grid textarea,
.module-card input, .module-card select, .module-card textarea {
  color: var(--text-main);
  background: var(--bg-light);
  border: 1px solid var(--border);
  font-family: 'Noto Sans TC', 'Outfit', sans-serif;
  outline: none;
}

.layout-grid input:focus, .layout-grid select:focus, .layout-grid textarea:focus,
.module-card input:focus, .module-card select:focus, .module-card textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.layout-grid input::placeholder, .layout-grid textarea::placeholder,
.module-card input::placeholder, .module-card textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.layout-grid select option, .module-card select option {
  background: var(--bg-white);
  color: var(--text-main);
}

/* Buttons should NOT be overridden */

input[type="submit"], input[type="button"], input[type="reset"],
input[type="file"], input[type="checkbox"], input[type="radio"],
input[type="range"], input[type="color"] {
  background: revert !important;
  color: revert !important;
  border: revert !important;
}

/* Number input spinners */

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
}

/* Labels */

label {
  color: var(--text-muted);
}

/* Auth page (dark login) keeps its own palette */

.auth-page-dark input, .auth-page-dark select, .auth-page-dark textarea {
  color: #fff !important;
  background: rgba(255,255,255,0.05) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
}

.auth-page-dark input::placeholder, .auth-page-dark textarea::placeholder {
  color: rgba(255,255,255,0.4) !important;
}

.auth-page-dark label {
  color: #aaa;
}

/* Glass / Card panels */

.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 500;
  font-family: 'Noto Sans TC', 'Outfit', sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  font-size: 0.95rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed !important;
  box-shadow: none !important;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--glass-bg);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-secondary {
  background: rgba(230, 126, 34, 0.1);
  color: var(--secondary);
  border: 1px solid rgba(230, 126, 34, 0.3);
}

.btn-secondary:hover {
  background: rgba(230, 126, 34, 0.2);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

h1, h2, h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: inherit;
}

.text-gradient {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Canvas Editor Area */

.canvas-container {
  position: relative;
  width: 100%;
  height: 600px;
  background: #fafaf8;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
  cursor: crosshair;
  border: 1px solid var(--border);
}

.canvas-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.layout-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: 100vh;
}

.sidebar {
  padding: 2rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-white);
}

.main-content {
  padding: 2rem;
  overflow-y: auto;
  background: var(--bg-light);
}

.mobile-header {
  display: none;
}

.sidebar-overlay {
  display: none;
}

.mobile-close-btn {
  display: none;
}

@media (max-width: 768px) {
  .layout-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    overflow: hidden;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    border-right: none;
    border-radius: 0;
  }
  
  .sidebar.mobile-open {
    left: 0;
  }

  .mobile-close-btn {
    display: block;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .sidebar-overlay.mobile-open {
    opacity: 1;
    visibility: visible;
  }

  .main-content {
    padding: 1rem;
    padding-top: 76px; /* Space for mobile header */
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 60px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  }

  .quote-grid {
    grid-template-columns: 1fr !important;
  }
  .quote-header {
    flex-direction: column;
    align-items: stretch !important;
  }
}

.quote-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
}

.quote-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.module-card {
  padding: 1.5rem;
  border-radius: 16px;
  background: var(--bg-white);
  border: 1px solid var(--glass-border);
  transition: all 0.3s ease;
  box-shadow: var(--card-shadow);
}

.module-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.1);
}

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(39, 174, 96, 0.1);
  color: var(--accent);
  border: 1px solid rgba(39, 174, 96, 0.2);
}

.step-indicator {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.step {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.step-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  transition: all 0.3s ease;
}

.step.active .step-number {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 0 15px var(--primary-glow);
}

.step-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.step.active .step-label {
  color: var(--text-main);
  font-weight: 500;
}

.floating-tools {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 20px;
  z-index: 10;
}

/* Animations */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.animate-pulse-slow {
  animation: pulse-slow 3s ease-in-out infinite;
}

@keyframes pulse-slow {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

/* ── RWD Fixes ── */

@media (max-width: 768px) {
  /* Settings page: stack tabs horizontally on top */
  .settings-layout {
    flex-direction: column !important;
  }
  .settings-tabs {
    width: 100% !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    gap: 6px !important;
    padding-bottom: 8px;
  }
  .settings-tabs button {
    white-space: nowrap;
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
  }

  /* CRM: stack stat cards */
  .crm-header {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .crm-stats {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .crm-stats > div {
    flex: 1 1 100px !important;
    min-width: 0 !important;
  }

  /* BidCenter: table grid stack */
  .bid-items-header,
  .bid-items-row {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }
  .bid-items-header {
    display: none !important;
  }

  /* General modal fixes */
  .modal-content {
    width: 95% !important;
    padding: 16px !important;
    max-height: 85vh !important;
  }

  /* Prevent overflow on all grids */
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns: 1fr 2fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns: 3fr 1fr 1fr 1fr auto"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── Reusable Modal Utilities ── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-white);
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 24px 30px;
}

.modal-content .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.modal-content .modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
}

.modal-content .modal-footer {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .main-content {
    padding: 0.75rem !important;
    padding-top: 72px !important;
  }
  h2 {
    font-size: 1.2rem !important;
  }
  .module-card {
    padding: 1rem !important;
  }
  .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
  }
}

@media print {
  .no-print, .sidebar {
    display: none !important;
  }
  body, .glass-panel, .card {
    background: white !important;
    color: black !important;
    border: none !important;
    box-shadow: none !important;
  }
  h2, h3, h4, p, label, input, textarea {
    color: black !important;
  }
  .layout-grid {
    display: block !important;
  }
  .main-content {
    padding: 0 !important;
  }
}

.animate-fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* Gantt Chart RWD */

@media (max-width: 768px) {
  .gantt-wrapper {
    overflow-x: auto !important;
  }
  .gantt-label-col {
    position: sticky !important;
    left: 0;
    z-index: 20 !important;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
  }
}

/* ── Utility Classes for RWD ── */

.w-full { width: 100%; }

.overflow-x-auto { overflow-x: auto; }

.hidden { display: none; }

@media (min-width: 768px) {
  .md\:block { display: block !important; }
  .md\:hidden { display: none !important; }
}

@media (max-width: 768px) {
  .quoter-wrapper {
    margin-top: -1.5rem !important;
  }
  .step-arrow {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .auth-card-container {
    padding: 1.5rem 1rem !important;
    border-radius: 12px !important;
  }
}
