/* LIGHT MODE VARIABLES (Default) */
:root {
  --bg-color: #f4f6f9;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #16a34a;
  --success-bg: #dcfce7;
  --danger-color: #dc2626;
  --danger-bg: #fee2e2;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --radius: 8px;
}

/* DARK MODE VARIABLES */
[data-theme="dark"] {
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --input-bg: #0f172a;
  --primary-color: #3b82f6;
  --primary-hover: #60a5fa;
  --success-color: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.15);
  --danger-color: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
}

/* Global Transition for smooth theme switching */
body, .card, input, select, .tab-btn {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg-color); color: var(--text-main); padding: 2rem 1rem; }

.app-container { max-width: 1000px; margin: 0 auto; }

/* Header & Controls */
.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.controls { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.theme-btn { background: var(--card-bg); color: var(--text-main); border: 1px solid var(--border-color); padding: 0.5rem 1rem; width: auto; font-size: 0.9rem; }
.theme-btn:hover { background: var(--border-color); }
.settings select { padding: 0.5rem; border-radius: var(--radius); border: 1px solid var(--border-color); font-weight: 600; background: var(--input-bg); color: var(--text-main); }

/* Tabs */
.tabs { display: flex; margin-bottom: 1.5rem; border-bottom: 2px solid var(--border-color); overflow-x: auto; white-space: nowrap; }
.tab-btn { background: none; border: none; padding: 0.75rem 1.5rem; font-size: 1rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; flex: 1; }
.tab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

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

/* Layout & Cards */
.calculator-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.5rem; }
.card { background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem; border: 1px solid var(--border-color); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }

/* Forms */
.form-group { margin-bottom: 1.2rem; display: flex; flex-direction: column; }
.form-group label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.4rem; color: var(--text-main); }
.form-group input, .form-group select { padding: 0.7rem; border: 1px solid var(--border-color); border-radius: 6px; background: var(--input-bg); color: var(--text-main); font-size: 1rem; }
.form-group input:focus { outline: 2px solid var(--primary-color); }
.form-row { display: flex; gap: 1rem; }
.flex-1 { flex: 1; } .flex-2 { flex: 2; }

/* Toggle */
.card-highlight { background: var(--bg-color); padding: 1rem; border-radius: 6px; border: 1px solid var(--border-color); }
.checkbox-group { flex-direction: row; align-items: center; gap: 0.75rem; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--text-muted); border-radius: 20px; transition: .3s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .3s; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(18px); }

/* Buttons */
button { border-radius: var(--radius); padding: 0.8rem; font-weight: 600; border: none; cursor: pointer; transition: 0.2s; width: 100%; font-size: 1rem; }
.primary-btn { background: var(--primary-color); color: white; margin-top: 1rem; }
.primary-btn:hover { background: var(--primary-hover); }
.success-btn { background: var(--success-color); color: white; width: auto; padding: 0.6rem 1.2rem; }
.success-btn:hover { filter: brightness(1.1); }
.success-btn:disabled { background: var(--border-color); color: var(--text-muted); cursor: not-allowed; }
.remove-btn { background: var(--danger-color); color: white; padding: 0.4rem 0.8rem; font-size: 0.8rem; width: auto; border-radius: 4px; }

/* Metrics & Lists */
.metric-card { background: var(--card-bg); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border-color); position: relative; text-align: center; margin-bottom: 1.5rem;}
.metric-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }
.metric-value { display: block; font-size: 2rem; font-weight: 800; margin-top: 0.5rem; }
.status-badge { position: absolute; top: 1rem; right: 1rem; font-size: 0.75rem; font-weight: 700; padding: 0.3rem 0.6rem; border-radius: 4px; }

.breakdown-list { list-style: none; margin-top: 1rem; }
.breakdown-list li { display: flex; justify-content: space-between; padding: 0.7rem 0; border-bottom: 1px dashed var(--border-color); font-size: 0.95rem; }
.total-row { border-bottom: none !important; border-top: 2px solid var(--text-main) !important; font-weight: 700; font-size: 1.15rem !important; }

/* Cart Table */
.cart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 1rem;}
.table-responsive { overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }
.cart-table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; min-width: 500px; }
.cart-table th, .cart-table td { padding: 1rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border-color); }
.cart-table th { background: var(--bg-color); font-weight: 600; font-size: 0.9rem; color: var(--text-muted); }
.cart-summary { display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; width: 100%;}
.summary-row { width: 100%; max-width: 300px; display: flex; justify-content: space-between; font-size: 1.1rem; }
.grand-total { font-weight: 700; font-size: 1.3rem; color: var(--primary-color); border-top: 2px solid var(--border-color); padding-top: 0.5rem; }

/* MOBILE RESPONSIVENESS (PHONES) */
@media (max-width: 768px) {
  body { padding: 1rem 0.5rem; }
  .header-top h1 { font-size: 1.5rem; text-align: center; width: 100%; }
  .controls { width: 100%; justify-content: space-between; }
  
  .calculator-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: 0; }
  .flex-1, .flex-2 { width: 100%; }
  
  .card { padding: 1rem; }
  .metric-value { font-size: 1.75rem; }
  
  .summary-row { max-width: 100%; }
  .cart-header h2 { font-size: 1.2rem; }
}

/* Print Styles */
.print-only { display: none; }
@media print {
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  body { padding: 0; background: white; color: black; }
  #print-invoice { max-width: 800px; margin: 0 auto; font-family: monospace; }
  .invoice-header { text-align: center; margin-bottom: 2rem; border-bottom: 2px dashed #000; padding-bottom: 1rem; }
  .invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }
  .invoice-table th, .invoice-table td { padding: 0.5rem; border-bottom: 1px solid #ccc; text-align: left; }
  .invoice-totals { text-align: right; font-size: 1.2rem; margin-bottom: 2rem; }
  .invoice-footer { text-align: center; font-size: 0.9rem; border-top: 1px dashed #000; padding-top: 1rem; }
}