/* ══════════════════════════════════════════════════════════════════
   MASTER WORKSPACE — Shared tab shell & layout
   ══════════════════════════════════════════════════════════════════ */
:root, html.mw-dark {
  --mw-bg: #0f172a;
  --mw-surface: #1e293b;
  --mw-surface-2: #334155;
  --mw-border: rgba(255,255,255,0.08);
  --mw-text: #e2e8f0;
  --mw-text-muted: #94a3b8;
  --mw-primary: #3b82f6;
  --mw-primary-hover: #2563eb;
  --mw-accent: #8b5cf6;
  --mw-tab-bg: #1e293b;
  --mw-tab-active: #3b82f6;
  --mw-tab-hover: #334155;
  --mw-header-bg: #0f172a;
  --mw-danger: #ef4444;
  --mw-success: #22c55e;
  --mw-shadow: 0 4px 24px rgba(0,0,0,0.3);
  --mw-radius: 8px;
  --mw-transition: all 0.2s ease;
}

html.mw-light {
  --mw-bg: #f1f5f9;
  --mw-surface: #ffffff;
  --mw-surface-2: #e2e8f0;
  --mw-border: rgba(0,0,0,0.1);
  --mw-text: #1e293b;
  --mw-text-muted: #64748b;
  --mw-primary: #2563eb;
  --mw-primary-hover: #1d4ed8;
  --mw-accent: #7c3aed;
  --mw-tab-bg: #ffffff;
  --mw-tab-active: #2563eb;
  --mw-tab-hover: #e2e8f0;
  --mw-header-bg: #ffffff;
  --mw-danger: #dc2626;
  --mw-success: #16a34a;
  --mw-shadow: 0 4px 24px rgba(0,0,0,0.1);
  --mw-radius: 8px;
  --mw-transition: all 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--mw-bg);
  color: var(--mw-text);
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
}

/* ═══ HEADER ═══ */
.mw-header {
  background: var(--mw-header-bg);
  border-bottom: 1px solid var(--mw-border);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

.mw-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mw-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--mw-text);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.mw-brand span {
  color: var(--mw-primary);
}

.mw-header-center {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mw-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ═══ TAB NAVIGATION ═══ */
.mw-tabs {
  display: flex;
  gap: 2px;
  background: var(--mw-surface);
  border-radius: var(--mw-radius);
  padding: 3px;
}

.mw-tab-btn {
  padding: 6px 18px;
  border: none;
  background: transparent;
  color: var(--mw-text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--mw-transition);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mw-tab-btn:hover {
  background: var(--mw-tab-hover);
  color: var(--mw-text);
}

.mw-tab-btn.active {
  background: var(--mw-tab-active);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}

.mw-tab-btn .mw-badge {
  background: rgba(255,255,255,0.15);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.mw-tab-btn.active .mw-badge {
  background: rgba(255,255,255,0.25);
}

/* ═══ PROJECT SELECTOR ═══ */
.mw-project-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mw-project-selector select {
  background: var(--mw-surface);
  color: var(--mw-text);
  border: 1px solid var(--mw-border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  max-width: 200px;
}

.mw-project-selector select:focus {
  outline: none;
  border-color: var(--mw-primary);
}

.mw-project-btn {
  padding: 5px 10px;
  border: 1px solid var(--mw-border);
  background: var(--mw-surface);
  color: var(--mw-text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: var(--mw-transition);
}

.mw-project-btn:hover {
  background: var(--mw-surface-2);
  border-color: var(--mw-primary);
}

/* ═══ MAIN CONTAINER ═══ */
.mw-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.mw-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: var(--mw-surface);
  border-bottom: 1px solid var(--mw-border);
  flex-shrink: 0;
}

.mw-toolbar .mw-sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--mw-text-muted);
}

.mw-toolbar .mw-sync-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mw-success);
  display: inline-block;
}

.mw-toolbar .mw-sync-status .dot.warning {
  background: #f59e0b;
}

.mw-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ═══ MODULE PANELS ═══ */
.mw-module-panel {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  position: absolute;
  top: 0;
  left: 0;
}

/* Ensure panel content is below the master header when overflown */
.mw-body {
  min-height: 0;
}

.mw-module-panel.active {
  display: block;
}

.mw-module-panel iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ═══ STATUS BAR ═══ */
.mw-status-bar {
  height: 24px;
  background: var(--mw-surface);
  border-top: 1px solid var(--mw-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11px;
  color: var(--mw-text-muted);
  gap: 16px;
  flex-shrink: 0;
}

.mw-status-bar .status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ═══ MODAL OVERRIDES ═══ */
.mw-modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mw-modal {
  background: var(--mw-surface);
  border: 1px solid var(--mw-border);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: var(--mw-shadow);
}

.mw-modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--mw-text);
}

.mw-modal input, .mw-modal select {
  width: 100%;
  padding: 8px 12px;
  background: var(--mw-bg);
  color: var(--mw-text);
  border: 1px solid var(--mw-border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}

.mw-modal input:focus, .mw-modal select:focus {
  outline: none;
  border-color: var(--mw-primary);
}

.mw-modal .btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .mw-header { padding: 0 12px; height: auto; min-height: 52px; flex-wrap: wrap; gap: 4px; }
  .mw-brand { font-size: 14px; }
  .mw-tab-btn { padding: 5px 10px; font-size: 12px; min-height: 36px; }
  .mw-tab-btn .tab-label-short { display: inline; }
  .mw-tab-btn .tab-label-full { display: none; }
  .mw-project-selector select { max-width: 120px; font-size: 12px; }
  .mw-linked-panel { width: 280px; }
  .mw-header-center { order: 3; width: 100%; justify-content: center; }
  .mw-tabs { width: 100%; justify-content: center; }
  .mw-modal { max-width: 95%; padding: 16px; }
  .mw-modal h2 { font-size: 16px; }
  .mw-modal input, .mw-modal select { font-size: 16px; padding: 10px 12px; }
  .mw-status-bar { height: auto; min-height: 28px; flex-wrap: wrap; padding: 4px 12px; }
  .mw-toolbar { flex-wrap: wrap; gap: 6px; padding: 6px 12px; }
  .mw-project-selector { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .mw-header { flex-direction: column; align-items: stretch; padding: 8px 12px; }
  .mw-header-left, .mw-header-right { justify-content: center; }
  .mw-header-right { gap: 8px; }
  .mw-brand { font-size: 13px; text-align: center; }
  .mw-tab-btn { flex: 1; justify-content: center; padding: 8px 6px; font-size: 11px; }
  .mw-modal { max-width: 100%; border-radius: 0; width: 100%; min-height: 100vh; padding: 12px; }
  .mw-modal-overlay { align-items: flex-start; overflow-y: auto; }
  .modal .modal-content { max-height: none !important; }
  .mw-project-selector select { max-width: 100px; font-size: 11px; }
  .mw-status-bar { font-size: 10px; gap: 8px; }
  .mw-toolbar .mw-sync-status { font-size: 10px; }
}

@media (max-width: 360px) {
  .mw-tab-btn { font-size: 10px; padding: 6px 4px; }
  .mw-brand { font-size: 12px; }
  .mw-project-selector select { max-width: 80px; font-size: 10px; }
  .mw-modal { padding: 8px; }
}

@media (min-width: 769px) {
  .mw-tab-btn .tab-label-short { display: none; }
  .mw-tab-btn .tab-label-full { display: inline; }
}

/* ═══ ESTIMATION MODULE OVERRIDES ═══ */

/* Ensure master workspace body keeps its layout */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif !important;
  background: var(--mw-bg) !important;
  min-height: 100vh !important;
  padding: 0 !important;
  line-height: 1.5 !important;
  overflow: hidden !important;
}

/* Module panels inherit proper scroll */
.mw-module-panel {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
}

.mw-module-panel .container {
  max-width: 1400px;
  margin: 0 auto;
}

/* ═══ CARRIAGE MODULE OVERRIDES ═══ */
/* Hide carriage topbar (its own header) — keep sidebar nav visible */
#panel-carriage #topbar,
#panel-carriage .topbar {
  display: none !important;
}
/* Adjust main-content to fill the space */
#panel-carriage #main-content {
  margin-top: 0 !important;
  height: 100% !important;
}

/* ═══ UTILITY ═══ */
.mw-hidden { display: none !important; }
.mw-text-primary { color: var(--mw-primary); }
.mw-text-success { color: var(--mw-success); }
.mw-text-danger { color: var(--mw-danger); }
.mw-text-muted { color: var(--mw-text-muted); }

/* Ensure master header stays above carriage sidebar in nav-top/bottom mode */
.mw-header {
  z-index: 300 !important;
}

/* ═══ MODAL — targets estimation modals (have .modal-content child), NOT carriage (.modal-header/.modal-body) ═══ */
.modal:has(.modal-content) {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 99999 !important;
}
.modal:has(.modal-content)[style*="display: none"],
.modal:has(.modal-content)[style*="display:none"] {
  display: none !important;
}
.modal:has(.modal-content) .modal-content {
  margin: auto !important;
  max-height: 90vh !important;
  overflow-y: auto !important;
  width: auto !important;
  min-width: 280px !important;
  max-width: 600px !important;
  border-radius: 12px !important;
}

/* When carriage nav is at top, shift sidebar below header */
body.nav-top #sidebar {
  top: 52px !important;
  height: calc(100% - 52px) !important;
}


/* Red close (×) buttons on all estimation modals */
.modal-content button[style*="border-radius:50%"][style*="position:absolute"] {
  color: red !important;
  background: rgba(255, 0, 0, 0.12) !important;
  font-size: 20px !important;
  font-weight: bold !important;
}
.modal-content button[style*="border-radius:50%"][style*="position:absolute"]:hover {
  background: rgba(255, 0, 0, 0.25) !important;
}
