/* Base Styles */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --radius: 6px;
  --radius-lg: 8px;
}

/* Dark mode colors */
[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary: #94a3b8;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --background: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
}

/* System preference detection when theme is "system" */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --secondary: #94a3b8;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --background: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
  }
}

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

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--background);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
}

.logo-icon {
  height: 40px;
  width: 40px;
  border-radius: 8px;
}

.logo-text {
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  transition: background 0.2s;
}

.nav-link:hover {
  background: var(--background);
}

/* Main Content */
.main {
  flex: 1;
  padding: 32px 0;
}

/* Footer */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  gap: 8px;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

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

.btn-secondary:hover {
  background: var(--background);
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 600;
}

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

/* Hero Section */
.hero {
  text-align: center;
  padding: 60px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: var(--radius-lg);
  margin-bottom: 40px;
}

.hero h1 {
  font-size: 36px;
  margin-bottom: 12px;
}

.hero-subtitle {
  font-size: 18px;
  opacity: 0.9;
  margin-bottom: 32px;
}

.hero-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

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

.hero .btn-secondary {
  background: transparent;
  color: white;
  border-color: rgba(255,255,255,0.5);
}

/* Features */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
}

.feature-card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.feature-card h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--primary);
}

.feature-card p {
  color: var(--text-muted);
}

/* Forms */
.form {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.form-section {
  margin-bottom: 32px;
}

.form-section h2 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-help {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.section-hint {
  display: block;
  margin-top: -8px;
  margin-bottom: 12px;
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group input {
  flex: 1;
  border-radius: 0;
}

.input-group input:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-group input:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.input-prefix,
.input-suffix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
}

.input-prefix {
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-suffix {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* Tier Grid */
.tier-grid {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tier-header {
  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  gap: 12px;
  padding: 10px 12px;
  background: var(--background);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.tier-row {
  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  align-items: center;
}

.tier-row input {
  padding: 8px 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tier-label {
  font-weight: 500;
  color: var(--text-muted);
}

.tier-note {
  font-size: 13px;
  color: var(--text-muted);
}

.tier-final {
  background: var(--background);
}

/* Tables */
.table-container {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 14px 16px;
  background: var(--background);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.data-table tbody tr:hover {
  background: var(--background);
}

.data-table .actions {
  display: flex;
  gap: 8px;
}

.inline-form {
  display: inline;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
}

.badge-premium {
  background: #dbeafe;
  color: #1e40af;
}

.badge-commission {
  background: #dcfce7;
  color: #166534;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-btn {
  padding: 8px 16px;
  font-size: 14px;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: all 0.2s;
}

.filter-btn:hover {
  background: var(--surface);
  color: var(--text);
}

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

.search-box {
  margin-left: auto;
}

.search-box input {
  padding: 8px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 200px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Alerts */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* Error Page */
.error-page {
  text-align: center;
  padding: 80px 20px;
}

.error-page h1 {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 16px;
}

.error-message {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* Calculator Results */
.result-container {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.result-project h2 {
  font-size: 24px;
  margin-bottom: 4px;
}

.client-name {
  opacity: 0.9;
}

.estimate-date {
  font-size: 14px;
  opacity: 0.8;
}

.result-summary {
  display: flex;
  gap: 24px;
}

.summary-item {
  text-align: right;
}

.summary-item .label {
  font-size: 12px;
  text-transform: uppercase;
  opacity: 0.8;
}

.summary-item .value {
  font-size: 24px;
  font-weight: 700;
}

.result-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.detail-section h3 {
  font-size: 14px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.detail-table {
  width: 100%;
}

.detail-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.detail-table td:last-child {
  text-align: right;
  font-weight: 500;
}

.tier-breakdown,
.adjustments-section,
.extra-section {
  padding: 0 24px 24px;
}

.tier-breakdown h3,
.adjustments-section h3,
.extra-section h3 {
  font-size: 14px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.tier-table {
  font-size: 14px;
}

.tier-table th {
  background: var(--background);
  padding: 10px 12px;
  text-align: left;
}

.tier-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.tier-table tfoot td {
  background: var(--background);
  font-weight: 600;
}

.result-totals {
  padding: 24px;
  background: var(--background);
  border-top: 1px solid var(--border);
}

.result-totals h3 {
  font-size: 14px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.total-box {
  text-align: center;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.total-box .total-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.total-box .total-value {
  font-size: 24px;
  font-weight: 700;
}

.premium-total .total-value {
  color: var(--primary);
}

.commission-total .total-value {
  color: var(--success);
}

.net-total .total-value {
  color: var(--text);
}

/* Change Section */
.change-section {
  padding: 20px 24px;
  background: #fffbeb;
  border-top: 1px solid #fcd34d;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.change-section h3 {
  font-size: 14px;
  color: #92400e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.change-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.change-item {
  text-align: center;
  padding: 12px;
  background: white;
  border-radius: var(--radius);
  border: 1px solid #fcd34d;
}

.change-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.change-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.change-increase .change-value {
  color: var(--danger);
}

.change-decrease .change-value {
  color: var(--success);
}

/* Recent Calculations */
.recent-calculations {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
}

.recent-calculations h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 500;
}

.recent-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
}

.recent-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.recent-info {
  flex: 1;
  min-width: 0;
}

.recent-project {
  display: block;
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-client {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-amounts {
  text-align: right;
  flex-shrink: 0;
}

.recent-premium {
  display: block;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary);
}

.recent-date {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.recent-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

.recent-item:hover .recent-remove {
  opacity: 1;
}

.recent-remove:hover {
  background: var(--danger);
  color: white;
}

/* Calculator Form */
.calculator-form .form-grid {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 900px) {
  .calculator-form .form-grid {
    grid-template-columns: 1fr;
  }

  .result-header {
    flex-direction: column;
    gap: 20px;
  }

  .result-summary {
    width: 100%;
    justify-content: space-around;
  }

  .result-details {
    grid-template-columns: 1fr;
  }

  .totals-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* Calculation Sections */
.calc-section {
  margin: 0 24px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.calc-section h3 {
  font-size: 13px;
  color: var(--primary);
  padding: 10px 14px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.calc-section .tier-table.compact {
  font-size: 13px;
}

.calc-section .tier-table.compact th,
.calc-section .tier-table.compact td {
  padding: 8px 12px;
}

.calc-subtotals {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  padding: 10px 14px;
  background: var(--background);
  font-size: 13px;
}

.calc-subtotals strong {
  color: var(--primary);
}

.comparison-note {
  background: #fef3c7;
  border-color: #f59e0b;
}

.comparison-note p {
  padding: 10px 14px;
  margin: 0;
  font-size: 13px;
}

/* Prior Bond Adjustment Table */
.change-table {
  margin-bottom: 20px;
}

.change-table th {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
  text-align: right;
  padding: 10px 12px;
}

.change-table th:first-child {
  text-align: left;
}

.change-table td {
  padding: 10px 12px;
  text-align: right;
}

.change-table td:first-child {
  text-align: left;
}

.change-table .prior-row td {
  color: var(--text-muted);
}

.change-table .amount-due-row {
  background: #fef3c7;
}

.change-table .amount-due-row td {
  border-top: 2px solid #f59e0b;
}

.change-table .change-increase {
  color: var(--danger);
}

.change-table .change-decrease {
  color: var(--success);
}

/* Amount Due Grid */
.amount-due-grid {
  margin-top: 16px;
}

.amount-due-grid .total-box {
  border: 2px solid #f59e0b;
}

.premium-due .total-value,
.commission-due .total-value,
.net-due .total-value {
  color: var(--text);
}

.due-positive .total-value {
  color: var(--danger);
}

.due-negative .total-value {
  color: var(--success);
}

.due-positive {
  background: #fef2f2;
}

.due-negative {
  background: #f0fdf4;
}

/* Comparison Details - Collapsible Section */
.comparison-details {
  margin: 0 24px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f9fafb;
}

.comparison-summary {
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}

.comparison-summary::-webkit-details-marker {
  display: none;
}

.comparison-summary::before {
  content: '\25B6';
  font-size: 10px;
  transition: transform 0.2s;
}

.comparison-details[open] .comparison-summary::before {
  transform: rotate(90deg);
}

.comparison-summary:hover {
  color: var(--text);
  background: #f1f5f9;
}

.comparison-toggle-text {
  flex: 1;
}

.comparison-content {
  padding: 0 16px 16px;
}

.comparison-content .calc-section {
  margin: 0;
  background: white;
}

.comparison-content .calc-section h3 {
  background: #fef3c7;
  color: #92400e;
}

/* ============================================
   SHARED VIEW STYLES
   ============================================ */

.shared-view .header-minimal {
  padding: 12px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.shared-view .header-minimal .logo-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.shared-header {
  text-align: center;
  margin-bottom: 32px;
}

.share-subtitle {
  color: var(--text-muted);
  font-size: 16px;
  margin-top: 4px;
}

.shared-result .result-summary {
  justify-content: center;
}

.totals-grid.single-total {
  grid-template-columns: 1fr;
  max-width: 300px;
  margin: 0 auto;
}

.disclaimer {
  padding: 16px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  background: var(--background);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}

.shared-calculator {
  max-width: 800px;
  margin: 0 auto;
}

/* Success Card */
.success-card {
  max-width: 600px;
  margin: 40px auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  text-align: center;
}

.success-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
}

.success-card h2 {
  margin: 0 0 8px;
  color: var(--text);
}

.success-card > p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.share-details {
  background: var(--background);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  text-align: left;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--text-muted);
  font-size: 14px;
}

.detail-value {
  font-weight: 500;
  color: var(--text);
}

.share-url-box {
  display: flex;
  gap: 12px;
  margin: 20px 0;
  align-items: center;
}

.share-url-input {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  font-family: monospace;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--text);
}

.share-url-input:focus {
  outline: none;
  border-color: var(--primary);
}

.copy-btn {
  white-space: nowrap;
}

.success-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* Error Page */
.error-page {
  max-width: 500px;
  margin: 80px auto;
  text-align: center;
  padding: 40px;
}

.error-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 24px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: bold;
}

.error-page h1 {
  margin: 0 0 16px;
  color: var(--text);
}

.error-message {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.error-help {
  font-size: 14px;
  color: var(--text-light);
}

/* Button success state */
.btn-success {
  background: var(--success) !important;
  border-color: var(--success) !important;
  color: white !important;
}

/* Section note */
.section-note {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 12px;
}

/* Support Page */
.support-section {
  margin-top: 40px;
}

.support-section h2 {
  font-size: 24px;
  margin-bottom: 20px;
  color: var(--text);
}

.feature-link {
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
}

.feature-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* API Documentation Styles */
.api-docs {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 40px;
}

@media (max-width: 900px) {
  .api-docs {
    grid-template-columns: 1fr;
  }
  .api-nav {
    position: static !important;
  }
}

.api-nav {
  position: sticky;
  top: 100px;
  align-self: start;
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.api-nav h3 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.api-nav ul {
  list-style: none;
}

.api-nav li {
  margin-bottom: 8px;
}

.api-nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background 0.2s;
}

.api-nav a:hover {
  background: var(--background);
  color: var(--primary);
}

.api-content {
  min-width: 0;
}

.api-section {
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.api-section h2 {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary);
}

.api-section h3 {
  font-size: 18px;
  color: var(--text);
  margin: 24px 0 12px;
}

.api-section h4 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 20px 0 10px;
}

.api-section p {
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.7;
}

.info-box {
  background: var(--background);
  padding: 16px 20px;
  border-radius: var(--radius);
  border-left: 4px solid var(--primary);
  margin: 20px 0;
}

.info-box code {
  background: var(--surface);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: var(--primary);
}

.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  line-height: 1.6;
  margin: 12px 0;
}

.code-block code {
  background: none;
  padding: 0;
  color: inherit;
}

.api-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.api-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--background);
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
}

.api-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.api-table code {
  background: var(--background);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  color: var(--primary-dark);
}

.endpoint {
  background: var(--background);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
  border: 1px solid var(--border);
}

.endpoint-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.endpoint-header code {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  padding: 6px 12px;
  border-radius: var(--radius);
}

.method {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.method.get {
  background: #dbeafe;
  color: #1e40af;
}

.method.post {
  background: #dcfce7;
  color: #166534;
}

.method.put {
  background: #fef3c7;
  color: #92400e;
}

.method.delete {
  background: #fee2e2;
  color: #991b1b;
}

.scope-badge {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: #e0e7ff;
  color: #3730a3;
}

.scope-badge.admin {
  background: #fce7f3;
  color: #9d174d;
}

.warning-text {
  color: var(--warning);
  font-weight: 500;
  font-size: 14px;
}

.method-examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.example-block h4 {
  margin-top: 0;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-body p {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.share-url-group {
  display: flex;
  gap: 8px;
}

.share-url-group .share-url-input {
  flex: 1;
}

.share-status {
  color: var(--success);
  font-size: 14px;
  margin-top: 12px;
}

/* Compact Form Grid for shared views */
.form-grid-compact {
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid-compact .form-section {
  margin-bottom: 0;
}

.form-grid-compact .form-section h2 {
  display: none;
}

@media (max-width: 600px) {
  .form-grid-compact {
    grid-template-columns: 1fr;
  }
}

/* Rates info section for shared view */
.rates-info {
  padding: 20px 24px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.rates-info h3 {
  margin-bottom: 12px;
}

/* Page subtitle */
.page-subtitle {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 16px;
}

/* Login Page */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.login-card {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.login-card h1 {
  margin-bottom: 8px;
  color: var(--primary);
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-form .form-group {
  text-align: left;
  margin-bottom: 20px;
}

.login-form .form-actions {
  border-top: none;
  padding-top: 0;
  justify-content: center;
}

.login-form .btn-lg {
  width: 100%;
}

.login-help {
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.login-help a {
  color: var(--primary);
  text-decoration: none;
}

.login-help a:hover {
  text-decoration: underline;
}

/* Nav form and button link (for logout) */
.nav-form {
  display: inline;
}

.btn-link {
  background: none;
  border: none;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  color: inherit;
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--background);
  border-radius: 20px;
  padding: 4px;
  margin-left: 8px;
}

.theme-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.theme-btn:hover {
  color: var(--text);
}

.theme-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* Hamburger Menu Button */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  z-index: 102;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile Navigation */
@media (max-width: 768px), (max-height: 500px) and (orientation: landscape) {
  .header .container {
    position: relative;
  }

  .menu-toggle {
    display: flex;
  }

  .nav-link-desktop {
    display: none;
  }

  .nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    height: 100vh;
    background: var(--surface);
    flex-direction: column;
    padding: 80px 20px 20px;
    gap: 4px;
    box-shadow: var(--shadow-lg);
    transition: right 0.3s ease;
    z-index: 101;
  }

  .nav.active {
    right: 0;
  }

  .nav-link {
    padding: 14px 16px;
    font-size: 16px;
    border-radius: var(--radius);
  }

  .nav-link:hover {
    background: var(--background);
  }

  .nav-form {
    width: 100%;
  }

  .nav-form .btn-link {
    width: 100%;
    text-align: left;
    padding: 14px 16px;
    font-size: 16px;
  }

  .theme-toggle {
    margin: 16px 0 0;
    width: 100%;
    justify-content: center;
  }

  .theme-btn {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
  }

  /* Overlay for mobile menu */
  .nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
  }

  .nav-overlay.active {
    display: block;
  }
}

/* Dark mode specific overrides for hardcoded colors */
[data-theme="dark"] .badge-premium,
[data-theme="system"] .badge-premium {
  background: #1e3a5f;
  color: #93c5fd;
}

[data-theme="dark"] .badge-commission,
[data-theme="system"] .badge-commission {
  background: #14532d;
  color: #86efac;
}

[data-theme="dark"] .change-section,
[data-theme="system"] .change-section {
  background: #422006;
  border-top-color: #a16207;
}

[data-theme="dark"] .change-section h3,
[data-theme="system"] .change-section h3 {
  color: #fcd34d;
}

[data-theme="dark"] .change-item,
[data-theme="system"] .change-item {
  background: var(--surface);
  border-color: #a16207;
}

[data-theme="dark"] .comparison-note,
[data-theme="system"] .comparison-note {
  background: #422006;
  border-color: #a16207;
}

[data-theme="dark"] .change-table th,
[data-theme="system"] .change-table th {
  background: #422006;
  color: #fcd34d;
}

[data-theme="dark"] .change-table .amount-due-row,
[data-theme="system"] .change-table .amount-due-row {
  background: #422006;
}

[data-theme="dark"] .change-table .amount-due-row td,
[data-theme="system"] .change-table .amount-due-row td {
  border-top-color: #a16207;
}

[data-theme="dark"] .amount-due-grid .total-box,
[data-theme="system"] .amount-due-grid .total-box {
  border-color: #a16207;
}

[data-theme="dark"] .comparison-content .calc-section h3,
[data-theme="system"] .comparison-content .calc-section h3 {
  background: #422006;
  color: #fcd34d;
}

[data-theme="dark"] .due-positive,
[data-theme="system"] .due-positive {
  background: #450a0a;
}

[data-theme="dark"] .due-negative,
[data-theme="system"] .due-negative {
  background: #052e16;
}

[data-theme="dark"] .method.get,
[data-theme="system"] .method.get {
  background: #1e3a5f;
  color: #93c5fd;
}

[data-theme="dark"] .method.post,
[data-theme="system"] .method.post {
  background: #14532d;
  color: #86efac;
}

[data-theme="dark"] .method.put,
[data-theme="system"] .method.put {
  background: #422006;
  color: #fcd34d;
}

[data-theme="dark"] .method.delete,
[data-theme="system"] .method.delete {
  background: #450a0a;
  color: #fca5a5;
}

[data-theme="dark"] .scope-badge,
[data-theme="system"] .scope-badge {
  background: #312e81;
  color: #a5b4fc;
}

[data-theme="dark"] .scope-badge.admin,
[data-theme="system"] .scope-badge.admin {
  background: #831843;
  color: #f9a8d4;
}

[data-theme="dark"] .alert-success,
[data-theme="system"] .alert-success {
  background: #052e16;
  color: #86efac;
  border-color: #166534;
}

[data-theme="dark"] .alert-error,
[data-theme="system"] .alert-error {
  background: #450a0a;
  color: #fca5a5;
  border-color: #991b1b;
}

/* Apply dark mode overrides when system prefers dark */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .badge-premium {
    background: #1e3a5f;
    color: #93c5fd;
  }

  [data-theme="system"] .badge-commission {
    background: #14532d;
    color: #86efac;
  }
}

/* ============================================
   SHARES PAGE - MOBILE RESPONSIVE
   ============================================ */

/* Mobile view hidden by default on desktop */
.shares-mobile {
  display: none;
}

/* Mobile styles */
@media (max-width: 768px) {
  /* Hide desktop table on mobile */
  .shares-desktop {
    display: none;
  }

  /* Show mobile view */
  .shares-mobile {
    display: block;
  }

  /* Empty state for mobile */
  .empty-state-mobile {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
  }

  .empty-state-mobile a {
    color: var(--primary);
    text-decoration: none;
  }

  .empty-state-mobile a:hover {
    text-decoration: underline;
  }

  /* Share cards container */
  .share-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  /* Individual share card */
  .share-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
  }

  .share-card:hover {
    box-shadow: var(--shadow-lg);
  }

  .share-card:active {
    transform: scale(0.98);
  }

  /* Card content (left side) */
  .share-card-content {
    flex: 1;
    min-width: 0;
  }

  .share-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
  }

  .share-card-name {
    font-size: 16px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .share-card-views {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .share-card-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .share-card-contractor {
    font-size: 14px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .share-card-rate {
    font-size: 13px;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Copy button (right side) */
  .share-card-action {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
  }

  .share-card-action:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
  }

  .share-card-action.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: white;
  }

  /* Page header adjustments for mobile */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header h1 {
    font-size: 24px;
  }

  .page-header .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================
   RATES PAGE MOBILE STYLES
   ============================================ */

/* Mobile view hidden by default (desktop shows table) */
.rates-mobile-view {
  display: none;
}

/* Mobile List Items */
.rates-mobile-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rate-mobile-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.rate-mobile-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.rate-mobile-item:active {
  background: var(--background);
}

.rate-mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.rate-mobile-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rate-mobile-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.rates-mobile-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  background: var(--surface);
  border-radius: var(--radius);
}

.rates-mobile-empty a {
  color: var(--primary);
  text-decoration: none;
}

.rates-mobile-empty a:hover {
  text-decoration: underline;
}

/* Rate Detail Modal */
.rate-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.rate-detail-modal.active {
  display: flex;
}

.rate-detail-modal .modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.rate-detail-modal .modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.rate-detail-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.rate-detail-modal .modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 16px;
}

.rate-detail-modal .modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.rate-detail-modal .modal-close:hover {
  background: var(--background);
  color: var(--text);
}

.rate-detail-modal .modal-body {
  padding: 20px;
}

.rate-detail-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rate-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--background);
  border-radius: var(--radius);
}

.rate-detail-label {
  font-size: 14px;
  color: var(--text-muted);
}

.rate-detail-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.rate-modal-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
}

/* Mobile breakpoint - show mobile view, hide desktop table */
@media (max-width: 768px) {
  .rates-desktop-view {
    display: none;
  }

  .rates-mobile-view {
    display: block;
  }

  /* Adjust filter bar for mobile rates page */
  .filter-bar {
    flex-wrap: wrap;
  }

  .filter-bar .search-box {
    width: 100%;
    margin-left: 0;
    margin-top: 8px;
  }

  .filter-bar .search-box input {
    width: 100%;
  }
}

/* ============================================
   MOBILE TABLE SCROLLING
   ============================================ */

@media (max-width: 768px) {
  /* Ensure tables maintain minimum width for readability when scrolling */
  .data-table,
  .tier-table,
  .detail-table,
  .change-table,
  .api-table {
    min-width: 500px;
  }

  /* Smaller min-width for simpler 2-column detail tables */
  .detail-table {
    min-width: 280px;
  }

  /* Tier grid (rate edit form) - ensure minimum width for scrolling */
  .tier-header,
  .tier-row {
    min-width: 400px;
  }

  /* Ensure calc sections have proper padding when scrolling */
  .calc-section {
    margin-left: 12px;
    margin-right: 12px;
  }

  /* Ensure result details can scroll */
  .result-details {
    padding: 16px;
  }

  /* Ensure change section can scroll */
  .change-section {
    padding: 16px;
  }
}
