/* Core Variable System & Dark/Light Premium Theme */
:root {
  --font-sans: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Modern HSL Color Palette */
  --bg-app: #f6f8fb;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  
  --primary: #0f172a;
  --primary-light: #1e293b;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --accent-glow: rgba(37, 99, 235, 0.15);
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.02);
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--primary);
  color: var(--text-inverse);
  padding: 16px 28px;
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 1.4rem;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 0 12px var(--accent-glow);
}

.logo-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-text span {
  font-size: 0.75rem;
  opacity: 0.7;
  letter-spacing: 1px;
}

.header-title-container {
  text-align: center;
}

.header-title-container h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-title-container p {
  font-size: 0.8rem;
  opacity: 0.6;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* Main Body */
.app-body {
  display: flex;
  flex: 1;
  padding: 24px;
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Sidebar */
.app-sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Main Content */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0; /* Prevents flex children from overflowing */
}

/* Cards */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
}

.card-header.justify-between {
  justify-content: space-between;
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-light);
}

.header-title-group p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Sheet Tabs */
.sheet-tabs {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
}

.sheet-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text-main);
  text-align: left;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.sheet-tab:hover {
  background-color: #f1f5f9;
  color: var(--primary);
}

.sheet-tab.active {
  background-color: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.sheet-tab-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.sheet-tab.active .sheet-tab-icon {
  background-color: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

/* Forms */
.form-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  grid-column: span 2;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.half {
  grid-column: span 1;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--text-main);
  background-color: #f8fafc;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea.form-input {
  resize: none;
}

/* Tech Assessment List */
.tech-assessment-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tech-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tech-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.icon-cost {
  background-color: #fff7ed;
  color: #ea580c;
}

.icon-profit {
  background-color: #f0fdf4;
  color: #16a34a;
}

.icon-total {
  background-color: #eef2ff;
  color: #4f46e5;
}

.icon-usd {
  background-color: #faf5ff;
  color: #9333ea;
}

.stat-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.stat-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.profit-input-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-input {
  width: 70px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.25rem;
  color: #16a34a;
  outline: none;
}

.stat-input:focus {
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.input-unit {
  font-weight: 600;
  color: #16a34a;
}

.usd-quote-container {
  display: flex;
  flex-direction: column;
}

.usd-rate-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.rate-input {
  width: 45px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 3px;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  text-align: center;
  font-weight: 600;
}

/* Cost Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.cost-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.cost-table th, 
.cost-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.cost-table th {
  background-color: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cost-table tbody tr {
  transition: background-color var(--transition-fast);
}

.cost-table tbody tr:hover {
  background-color: #f8fafc;
}

.cell-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  background-color: transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-main);
  transition: all var(--transition-fast);
}

.cell-input:hover {
  background-color: #f1f5f9;
}

.cell-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.cell-input-num {
  text-align: right;
  font-weight: 600;
}

.cell-val-bold {
  font-weight: 700;
  color: var(--primary);
  text-align: right;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
}

.btn-primary {
  background-color: var(--accent);
  color: white;
}

.btn-primary:hover {
  background-color: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  background-color: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
  color: var(--primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-danger {
  background-color: #fee2e2;
  color: #ef4444;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-danger:hover {
  background-color: #ef4444;
  color: white;
}

/* Grid layout */
.grid-2-col {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
}

/* Chart */
.chart-container-el {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
}

/* History Timeline */
.history-timeline {
  padding: 20px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.timeline-item {
  display: flex;
  gap: 14px;
  position: relative;
}

.timeline-item::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 16px;
  bottom: -22px;
  width: 2px;
  background-color: var(--border-color);
}

.timeline-item:last-child::after {
  display: none;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--accent);
  margin-top: 4px;
  flex-shrink: 0;
  z-index: 2;
  box-shadow: 0 0 0 4px #eff6ff;
}

.timeline-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timeline-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.timeline-operator {
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--text-main);
}

.timeline-desc {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 500;
}

.timeline-diff {
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: #f8fafc;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px dashed var(--border-color);
  margin-top: 4px;
  font-family: monospace;
}

/* Notifications */
.notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--primary);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.notification.show {
  opacity: 1;
  transform: translateY(0);
}

/* Print Styles */
@media print {
  body {
    background-color: white;
    color: black;
  }
  .app-header, 
  .app-sidebar,
  .btn,
  .chart-card,
  .history-card,
  .rate-input,
  .profit-input-container input,
  .btn-danger {
    display: none !important;
  }
  .app-body {
    padding: 0;
  }
  .app-main {
    width: 100%;
  }
  .card {
    border: none;
    box-shadow: none;
  }
  .cost-table th {
    background-color: #eee !important;
    color: black;
  }
  .cost-table td, .cost-table th {
    border-bottom: 1px solid #999;
  }
}
