/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a56a0;
  --primary-light: #2d7dd2;
  --primary-dark: #0f3460;
  --accent: #f5a623;
  --accent-light: #ffd580;
  --success: #27ae60;
  --success-light: #d4edda;
  --danger: #e74c3c;
  --warning: #f39c12;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface2: #f0f4fa;
  --border: #dde3ee;
  --text: #1a2340;
  --text-muted: #6b7a99;
  --shadow: 0 2px 12px rgba(26,86,160,0.10);
  --shadow-lg: 0 4px 24px rgba(26,86,160,0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Segoe UI', 'Arial', sans-serif;
}

html {
  direction: rtl;
  font-family: var(--font);
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

body { min-height: 100vh; }

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
  color: white;
  padding: 2.5rem 1.5rem 3.5rem;
  text-align: center;
  position: relative;
}
.site-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 40px;
  background: var(--bg);
  clip-path: ellipse(55% 100% at 50% 100%);
  z-index: 0;
}
.site-header h1,
.site-header p,
.site-header .header-icon {
  position: relative;
  z-index: 1;
}
.site-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.site-header h1 span { color: var(--accent-light); }
.site-header p {
  font-size: 1.1rem;
  opacity: 0.88;
  max-width: 560px;
  margin: 0 auto;
}
.header-icon { font-size: 3rem; margin-bottom: 0.75rem; display: block; }

/* ===== MAIN LAYOUT ===== */
.main-container {
  max-width: 930px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.card-header .step-badge {
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 50%;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}
.card-header .chevron {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.card-header.open .chevron { transform: rotate(180deg); }
.card-body { padding: 1.25rem; }
.card-body.collapsed { display: none; }

/* ===== INSTRUCTIONS ===== */
.instructions-steps { counter-reset: step; list-style: none; }
.instructions-steps li {
  counter-increment: step;
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px dashed var(--border);
  align-items: flex-start;
}
.instructions-steps li:last-child { border-bottom: none; }
.instructions-steps li::before {
  content: counter(step);
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 50%;
  min-width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.instructions-steps li strong { display: block; margin-bottom: 0.2rem; }
.instructions-steps li small { color: var(--text-muted); font-size: 0.85rem; }
.iec-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.iec-link:hover { text-decoration: underline; }

/* ===== FILE UPLOAD ===== */
.saved-file-notice {
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #eef4ff;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1.5px solid var(--primary-light);
  flex-wrap: wrap;
}
.saved-file-icon { font-size: 1.4rem; flex-shrink: 0; }
.saved-file-info { flex: 1; font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-file-actions { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }
.btn-restore {
  padding: 0.4rem 0.9rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
}
.btn-restore:hover { opacity: 0.85; }
.btn-delete-saved {
  padding: 0.35rem 0.6rem;
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.btn-delete-saved:hover { background: var(--danger); color: white; }

.upload-zone {
  border: 2.5px dashed var(--primary-light);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  background: var(--surface2);
  position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  background: #e8f0fb;
  border-color: var(--primary);
}
.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%; height: 100%;
}
.upload-icon { font-size: 2.5rem; margin-bottom: 0.5rem; color: var(--primary-light); }
.upload-zone h3 { font-size: 1.1rem; margin-bottom: 0.3rem; }
.upload-zone p { font-size: 0.9rem; color: var(--text-muted); }

.file-info {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  margin-top: 1rem;
  border: 1px solid #a8d5b5;
}
.file-info.visible { display: flex; }
.file-info .file-icon { font-size: 1.5rem; flex-shrink: 0; }
.file-info > div { min-width: 0; overflow: hidden; }
.file-info .file-name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info .file-meta { font-size: 0.82rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== SETTINGS ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) { .settings-grid { grid-template-columns: 1fr; } }

.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.form-group input, .form-group select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  direction: rtl;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ===== PERIOD SELECTOR ===== */
.period-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.period-tab {
  padding: 0.5rem 1.2rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-muted);
  transition: all 0.15s;
}
.period-tab:hover { border-color: var(--primary-light); color: var(--primary); }
.period-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.period-picker { display: none; }
.period-picker.visible { display: block; }

/* ===== ANALYZE BUTTON ===== */
.btn-analyze {
  display: block;
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: var(--shadow);
  font-family: var(--font);
  margin-top: 0.5rem;
}
.btn-analyze:hover { opacity: 0.92; }
.btn-analyze:active { transform: scale(0.99); }
.btn-analyze:disabled { opacity: 0.5; cursor: not-allowed; }



.results-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 600px) { .results-summary { grid-template-columns: 1fr 1fr; } }

.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
}
.summary-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.summary-card .value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary-dark);
}
.summary-card .unit { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.1rem; }

/* ===== RESULTS TABLE ===== */
.results-card {
  overflow: hidden;
  border-radius: 0;
}

#resultsTable {
  margin-inline: 20px;
}
.results-header {
  padding: 1rem 1.25rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.results-header h2 { font-size: 1.15rem; font-weight: 700; }
.results-header small { font-size: 0.82rem; color: var(--text-muted); }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead th {
  background: var(--primary-dark);
  color: white;
  padding: 0.75rem 0.9rem;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:hover { background: var(--surface2); }
tbody tr.baseline-row { background: #fff8e1; }
tbody tr.best-row { background: #e8f5e9; }
tbody td {
  padding: 0.75rem 0.9rem;
  vertical-align: middle;
}
.company-cell { font-weight: 700; white-space: nowrap; }
.plan-cell { white-space: nowrap; }
.condition-badge {
  display: inline-block;
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #856404;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.3rem;
}
.savings-positive { color: var(--success); font-weight: 700; }
.savings-zero { color: var(--text-muted); }
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
}
.rank-1 { background: #ffd700; color: #5a4000; }
.rank-2 { background: #c0c0c0; color: #3a3a3a; }
.rank-3 { background: #cd7f32; color: white; }
.rank-other { background: var(--surface2); color: var(--text-muted); }

/* ===== RESULTS VISIBILITY ===== */
#results { display: none; }
#results.visible { display: block; }

/* ===== BEST PLAN BANNER ===== */
.best-plan-banner {
  background: linear-gradient(135deg, var(--success) 0%, #2ecc71 100%);
  color: white;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  display: none;
}
.best-plan-banner.visible { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.best-plan-banner .trophy { font-size: 2.5rem; flex-shrink: 0; }
.best-plan-banner h3 { font-size: 1.15rem; margin-bottom: 0.2rem; }
.best-plan-banner p { font-size: 0.9rem; opacity: 0.92; }
.best-plan-banner .savings-amount {
  font-size: 1.8rem;
  font-weight: 800;
  margin-right: auto;
  text-align: left;
}

/* ===== NOTE BOX ===== */
.note-box {
  background: #fff8e1;
  border: 1px solid #ffcc02;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: #5a4000;
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}
.note-box .note-icon { flex-shrink: 0; }

/* ===== FOOTER ===== */
.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.site-footer a { color: var(--primary-light); text-decoration: none; }

/* ===== LOADING ===== */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}
.loading-overlay.visible { display: flex; }
.spinner {
  width: 48px; height: 48px;
  border: 5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-weight: 600; color: var(--primary-dark); }

/* ===== ERROR ===== */
.error-box {
  display: none;
  background: #ffeaea;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #721c24;
  margin-top: 1rem;
  gap: 0.5rem;
  align-items: center;
}
.error-box.visible { display: flex; }

.site-footer .disclaimer {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  color: #5a4000;
  font-size: 0.83rem;
  margin-bottom: 0.75rem;
}


/* ===== MOBILE EXPANDABLE TABLE ===== */
.detail-row { display: none; }

@media (max-width: 1300px) {
  #resultsTable { margin-inline: 0; max-width: 100%; }
  .col-mobile-hide { display: none; }
  tbody tr { cursor: pointer; }
  tbody tr.detail-row { cursor: default; }
  .table-wrap { overflow-x: hidden; }
  thead th { white-space: normal; }
  .company-cell, .plan-cell { white-space: normal; word-break: break-word; }
  tr.row-expanded + .detail-row { display: table-row; }
  .detail-row td { background: var(--surface2) !important; padding: 0 !important; border-bottom: 2px solid var(--primary-light); }
  .detail-content { padding: 0.6rem 0.9rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; border-top: 1px dashed var(--border); }
  .detail-item { display: flex; flex-direction: column; gap: 0.1rem; min-width: 100px; }
  .detail-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }
  .detail-value { font-size: 0.88rem; font-weight: 600; color: var(--text); }
  .site-header h1 { font-size: 1.6rem; }
  .results-summary { grid-template-columns: 1fr 1fr; }
  table { font-size: 0.8rem; }
  thead th, tbody td { padding: 0.55rem 0.6rem; }
}
