:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --accent: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dcdde1;
  --header-h: 48px;
}

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

body {
  font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  -webkit-app-region: drag;
}

.app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.app-header .version {
  font-size: 11px;
  opacity: 0.7;
}

/* Tab Navigation */
.tab-nav {
  display: flex;
  background: #1e3a5f;
  border-bottom: 2px solid var(--primary);
  -webkit-app-region: no-drag;
}

.tab-btn {
  padding: 10px 24px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
  position: relative;
}

.tab-btn:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.05);
}

.tab-btn.active {
  color: white;
  border-bottom-color: var(--accent);
  background: rgba(255,255,255,0.1);
}

.tab-btn .badge {
  font-size: 10px;
  background: var(--accent);
  color: white;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
}

/* Main Content */
.main-content {
  height: calc(100vh - var(--header-h) - 43px);
  overflow-y: auto;
  padding: 16px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.card-header {
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 13px;
  border-radius: 6px 6px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header.green { background: var(--accent); }
.card-header.orange { background: var(--warning); }

.card-body {
  padding: 16px;
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input, .form-group select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(41,128,185,0.15);
}

.form-group .unit {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

/* Buttons */
.btn {
  padding: 8px 20px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

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

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

.btn-success:hover { background: #219a52; }

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

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* Table */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table th {
  background: var(--primary);
  color: white;
  padding: 8px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

table th.sub-header {
  background: #2471a3;
  font-size: 10px;
}

table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: center;
}

table tbody tr:hover {
  background: #eaf2f8;
}

table tbody tr:nth-child(even) {
  background: #fafbfc;
}

table tbody tr:nth-child(even):hover {
  background: #eaf2f8;
}

table td input {
  width: 100%;
  border: 1px solid transparent;
  padding: 4px 6px;
  text-align: center;
  font-size: 12px;
  background: transparent;
  border-radius: 3px;
}

table td input:focus {
  border-color: var(--primary-light);
  background: white;
  outline: none;
}

table td input.invalid {
  border-color: var(--danger);
  background: #fde8e8;
}

table td select {
  width: 100%;
  border: 1px solid transparent;
  padding: 4px 2px;
  text-align: center;
  font-size: 12px;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
}

table td select:focus {
  border-color: var(--primary-light);
  background: white;
}

.id-link {
  color: var(--primary-light);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.id-link:hover {
  color: var(--primary);
}

/* Results badges */
.badge-safe {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #d4efdf;
  color: #1e8449;
}

.badge-fail {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #f9e0e0;
  color: #c0392b;
}

.badge-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-oneway { background: #fdebd0; color: #b7950b; }
.badge-twoway { background: #d6eaf8; color: #2471a3; }

/* Result cells */
.result-value {
  font-weight: 600;
  font-family: 'Consolas', 'Courier New', monospace;
}

/* Modal / Detail Panel */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding-top: 40px;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  margin-bottom: 40px;
}

.modal-header {
  padding: 16px 20px;
  background: var(--primary);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px 8px 0 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.modal-header h2 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover { opacity: 0.8; }

.modal-body {
  padding: 20px;
}

/* Report Styles */
.report-section {
  margin-bottom: 20px;
}

.report-section h3 {
  font-size: 14px;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.report-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dotted #eee;
  align-items: baseline;
}

.report-row .label {
  color: var(--text-light);
  flex: 1;
}

.report-row .formula {
  flex: 1;
  text-align: center;
  font-family: 'Cambria Math', 'Times New Roman', serif;
  font-style: italic;
  color: #555;
}

.report-row .value {
  flex: 0 0 160px;
  text-align: right;
  font-weight: 600;
  font-family: 'Consolas', monospace;
}

.report-row .value .unit {
  color: var(--text-light);
  font-weight: 400;
  margin-left: 4px;
}

.report-remark {
  padding: 8px 12px;
  border-radius: 4px;
  font-weight: 600;
  margin-top: 8px;
}

.report-remark.safe {
  background: #d4efdf;
  color: #1e8449;
  border-left: 4px solid #27ae60;
}

.report-remark.fail {
  background: #f9e0e0;
  color: #c0392b;
  border-left: 4px solid #e74c3c;
}

/* MathJax */
.mathjax-container {
  overflow-x: auto;
  padding: 8px 0;
}

/* Action bar */
.action-bar {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  align-items: center;
  flex-wrap: wrap;
}

.action-bar .spacer { flex: 1; }

/* Steel Deck Properties Display */
.deck-props-display {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
}

.deck-props-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 12px;
}

.prop-label {
  color: var(--text-light);
  font-weight: 500;
  white-space: nowrap;
}

.prop-value {
  font-weight: 600;
  color: var(--text);
  font-family: 'Consolas', 'Courier New', monospace;
}

/* Steel Deck specific */
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #95a5a6; }

/* Print styles */
@media print {
  .app-header, .tab-nav, .action-bar, .btn { display: none !important; }
  .main-content { height: auto; overflow: visible; }
  .modal { max-height: none; box-shadow: none; }
  .modal-overlay { position: static; background: none; padding: 0; }
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.toolbar .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-right: 4px;
}

/* Summary row in table */
.summary-row td {
  font-weight: 700;
  background: #eaf2f8 !important;
  border-top: 2px solid var(--primary);
}

/* Status indicators */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.status-dot.ok { background: var(--accent); }
.status-dot.warn { background: var(--warning); }
.status-dot.fail { background: var(--danger); }

/* Handsontable overrides */
#rc-hot-container {
  width: 100%;
  overflow: hidden;
}

#rc-hot-container .handsontable {
  font-size: 12px;
  font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#rc-hot-container .handsontable th {
  background: var(--primary) !important;
  color: white !important;
  font-weight: 600;
  font-size: 11px;
  text-align: center;
  vertical-align: middle;
  padding: 6px 4px;
}

#rc-hot-container .handsontable td {
  text-align: center;
  vertical-align: middle;
  padding: 4px 6px;
}

#rc-hot-container .handsontable .htDimmed {
  color: var(--text);
}

/* Case Dropdown */
.case-dropdown {
  background: white;
  border: 2px solid var(--primary);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
  width: 260px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px 0;
}

.case-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.1s;
  border-left: 3px solid transparent;
}

.case-dropdown-item:hover {
  background: #eaf2f8;
  border-left-color: var(--primary);
}

.case-dropdown-item.selected {
  background: #d5f5e3;
  border-left-color: var(--accent);
}

.case-dropdown-label {
  font-size: 11px;
  font-weight: 600;
  color: #34495e;
  white-space: nowrap;
}

/* Action separator */
.action-separator {
  width: 1px;
  height: 24px;
  background: #bdc3c7;
  margin: 0 4px;
}

/* Schedule drawing table */
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.schedule-table th, .schedule-table td {
  border: 1px solid #333;
  padding: 6px 8px;
  text-align: center;
}
.schedule-table th {
  background: #f5f5f5;
  font-weight: 700;
  font-size: 11px;
}

/* Coefficient table in report */
.coeff-table {
  width: auto;
  margin: 0 auto;
  border-collapse: collapse;
  font-size: 13px;
}
.coeff-table th, .coeff-table td {
  border: 1px solid #ccc;
  padding: 6px 14px;
  text-align: center;
}
.coeff-table th {
  background: var(--primary);
  color: white;
  font-size: 11px;
}
.coeff-table td {
  font-family: 'Consolas', monospace;
}
