/* ===== Design Tokens ===== */
:root {
  --slate: #465563;
  --slate-dark: #2f3d49;
  --slate-light: #5a7085;
  --blue: #658DAD;
  --blue-light: #e8f0f6;
  --blue-pale: #f3f7fa;
  --green: #547E59;
  --green-light: #eaf3eb;
  --orange: #F2A16A;
  --orange-light: #fef4ec;
  --purple: #A68DB9;
  --purple-light: #f4eff8;
  --gray: #ADADAD;
  --gray-light: #e9ecef;
  --bg: #f5f7f9;
  --white: #ffffff;
  --danger: #c0392b;
  --text-primary: #2c3e50;
  --text-secondary: #5f6b7a;
  --text-muted: #8e99a4;
  --border: #dfe3e8;
  --border-light: #eef1f4;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(70,85,99,.1);
  --shadow-lg: 0 8px 32px rgba(70,85,99,.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  --transition: 180ms ease;
}

/* ===== Reset & Base ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout Container ===== */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ===== Site Header ===== */
.site-header {
  background: var(--white);
  color: var(--text-primary);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border-bottom: 2px solid var(--border-light);
}
.site-header .header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
}
.site-header .brand {
  display: flex;
  align-items: center;
}
.brand-logo {
  height: 56px;
  width: auto;
}
.site-header .header-session {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.site-header .header-session span {
  color: var(--text-muted);
}
.site-header .header-session button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: .2px;
}
.site-header .header-session button:hover {
  background: var(--bg);
  border-color: var(--slate-light);
  color: var(--text-primary);
}

/* ===== Hero / Page Title ===== */
.hero {
  background: linear-gradient(135deg, var(--slate-dark) 0%, var(--slate) 40%, var(--blue) 100%);
  color: var(--white);
  padding: 56px 32px 48px;
  margin: 0 -24px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(101,141,173,.15) 0%, transparent 70%);
  pointer-events: none;
}
.hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue) 0%, var(--green) 50%, var(--orange) 100%);
  opacity: .5;
}
.hero h1 {
  margin: 0 0 12px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.4px;
  line-height: 1.2;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}
.hero p {
  margin: 0;
  opacity: .75;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: .2px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 250ms ease;
}
.card:hover {
  box-shadow: var(--shadow-md);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.card-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -.1px;
}
.card-header .badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* Legacy h2 inside cards without card-header wrapper */
.card > h2:first-child {
  margin: 0 0 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

h2 { margin-top: 0; color: var(--text-primary); font-size: 17px; font-weight: 600; letter-spacing: -.1px; }
h3 {
  color: var(--slate);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 0 0 14px;
}

/* ===== Section Accents (left-border) ===== */
.accent-blue { border-left: 3px solid var(--blue); padding-left: 16px; }
.accent-green { border-left: 3px solid var(--green); padding-left: 16px; }
.accent-purple { border-left: 3px solid var(--purple); padding-left: 16px; }
.accent-orange { border-left: 3px solid var(--orange); padding-left: 16px; }

/* ===== Layout Helpers ===== */
.row { display: flex; gap: 20px; flex-wrap: wrap; }
.split > div { flex: 1; min-width: 300px; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* ===== Form Elements ===== */
label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 14px;
}
input, textarea, select {
  display: block;
  width: 100%;
  padding: 9px 12px;
  margin: 5px 0 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(101,141,173,.12);
}
input[type="file"] {
  padding: 8px;
  border-style: dashed;
  border-color: var(--gray);
  background: var(--bg);
  cursor: pointer;
}
input[type="file"]:hover {
  border-color: var(--blue);
  background: var(--blue-pale);
}
textarea {
  min-height: 80px;
  font-family: var(--font-mono);
  font-size: 12px;
  resize: vertical;
}

/* ===== Buttons ===== */
button {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 10px 20px;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: .2px;
}
button:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
button:active { transform: translateY(0); }

.btn-primary {
  background: var(--green);
  color: var(--white);
}
.btn-primary:hover { background: #4a7150; }

.btn-secondary {
  background: var(--slate);
  color: var(--white);
}
.btn-secondary:hover { background: var(--slate-dark); }

.btn-accent {
  background: var(--purple);
  color: var(--white);
}
.btn-accent:hover { background: #9580a8; }

.btn-outline {
  background: transparent;
  color: var(--slate);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--gray); }

.btn-warning {
  background: var(--orange);
  color: var(--text-primary);
}
.btn-warning:hover { background: #e89558; }

/* Button bar spacing */
.btn-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* Legacy button IDs for JS onclick compatibility */
#saveSwapBtn { background: var(--orange); color: var(--text-primary); }
#saveSwapBtn:hover { background: #e89558; }
#saveSettingsBtn { background: var(--orange); color: var(--text-primary); }
#parseConfirmationBtn { background: var(--purple); color: var(--white); }
#parseConfirmationBtn:hover { background: #9580a8; }

/* Excel export button */
.btn-excel {
  background: #1D6F42;
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  gap: 5px;
}
.btn-excel:hover { background: #185a36; }
.btn-excel svg { flex-shrink: 0; }

/* ===== Leg Panels ===== */
.leg-panel {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 20px;
  border: 1px solid var(--border-light);
}
.leg-panel h3 {
  margin: 0 0 16px;
}
.leg-panel.fixed-leg {
  border-top: 3px solid var(--blue);
}
.leg-panel.floating-leg {
  border-top: 3px solid var(--green);
}

/* ===== Summary Banner ===== */
#summary {
  font-weight: 600;
  font-size: 14px;
  background: linear-gradient(135deg, var(--slate-dark), var(--slate));
  color: var(--white);
  padding: 18px 22px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  line-height: 1.7;
}

/* ===== Tables ===== */
table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
thead th {
  background: var(--slate-dark);
  color: var(--white);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 6px 6px;
  text-align: right;
  border: none;
  border-bottom: 2px solid var(--slate);
  white-space: nowrap;
}
thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

td {
  padding: 5px 6px;
  text-align: right;
  border: none;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  white-space: nowrap;
}
th:nth-child(-n+3), td:nth-child(-n+3) { text-align: left; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--blue-pale); }
tbody tr:nth-child(even) { background: var(--bg); }
tbody tr:nth-child(even):hover { background: var(--blue-pale); }

/* Net table specific */
#netTable td:last-child,
#netTable th:last-child { text-align: right; }
#netTable td:first-child { text-align: left; }
#netTable th:first-child { text-align: left; }

/* Results leg panels */
.results-grid {
  display: grid;
  grid-template-columns: 5fr 7fr auto;
  gap: 10px;
  align-items: start;
  overflow-x: auto;
}
.results-grid > div > h3 {
  margin-bottom: 10px;
}
@media (max-width: 900px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Notional Schedule Table ===== */
.sheet th, .sheet td { text-align: left; }
.sheet input { margin: 0; }
.sheet .removeRowBtn {
  background: var(--gray-light);
  color: var(--text-secondary);
  padding: 5px 10px;
  font-size: 12px;
}
.compact-schedule { font-size: 12px; }
.compact-schedule th { padding: 6px 10px; font-size: 11px; }
.compact-schedule td { padding: 5px 10px; }
.compact-schedule td:last-child { text-align: right; }

/* ===== Collapsible Sections ===== */
details {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  overflow: hidden;
}
details summary {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--bg);
  transition: background var(--transition);
  user-select: none;
}
details summary:hover { background: var(--blue-pale); color: var(--slate); }
details[open] summary { border-bottom: 1px solid var(--border-light); }
details > textarea, details > pre {
  margin: 0;
  border: none;
  border-radius: 0;
}

/* ===== Account Section ===== */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.account-box {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-light);
}
.account-box h3 {
  margin-bottom: 12px;
}
.delivery-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
@media (max-width: 600px) {
  .delivery-row { grid-template-columns: 1fr; }
}

/* ===== Status / Notes ===== */
.note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
#sofrStatus {
  font-size: 12px;
  color: var(--text-muted);
}
#parseStatus {
  margin-top: 10px;
}

/* ===== Saved Swaps ===== */
ul#savedSwaps {
  padding-left: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
ul#savedSwaps li {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}
ul#savedSwaps li:hover { background: var(--blue-pale); }
ul#savedSwaps li.saved-swap-empty {
  grid-column: 1 / -1;
}
.saved-swap-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.saved-swap-name:hover { text-decoration: underline; }
.saved-swap-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.saved-swap-actions button {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-rename {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  font-size: 11px;
  padding: 3px 8px;
}
.btn-rename:hover {
  background: var(--border-light);
  color: var(--text);
}
.btn-delete {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-size: 11px;
  padding: 3px 8px;
}
.btn-delete:hover {
  background: var(--danger);
  color: var(--white);
}

/* ===== Diagnostic Section ===== */
.diagnostics-card {
  opacity: .85;
  transition: opacity var(--transition);
}
.diagnostics-card:hover { opacity: 1; }

/* ===== File Upload Area ===== */
.upload-area {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.upload-area input[type="file"] {
  flex: 1;
  min-width: 200px;
}

/* ===== Footer ===== */
.site-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 24px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: .2px;
}
.site-footer .footer-divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 0 0 20px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .page-container { padding: 0 12px 24px; }
  .hero { padding: 36px 16px 32px; margin: 0 -12px; }
  .hero h1 { font-size: 24px; }
  .card { padding: 18px 16px; }
  .split > div { min-width: 100%; }
  .leg-panel { padding: 14px; }
}

/* ===== Print ===== */
@media print {
  .site-header, .btn-bar, button, .upload-area, .diagnostics-card,
  #saveSwapBtn, #calculateBtn, .account-grid, .delivery-row,
  #accountCard, #ownerPortalCard, #savedSwapsCard, .site-footer { display: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
}
