/* ==========================================================================
   КБ ИНЖЕНЕР — Industrial CAD Dark Theme Stylesheet
   ========================================================================== */

:root {
  --bg-cad-base: #0c0e12;
  --bg-cad-surface: #14181f;
  --bg-cad-panel: #1a202a;
  --bg-cad-card: #222936;
  --bg-cad-hover: #2b3445;

  --border-cad-dim: #262f3e;
  --border-cad-main: #374357;
  --border-cad-bright: #4c5d77;

  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.25);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.25);
  --accent-green: #10b981;
  --accent-red: #ef4444;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-amber: #fbbf24;
  --text-cyan: #38bdf8;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

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

body.cad-theme {
  background-color: var(--bg-cad-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Blueprint Fine Grid Background */
.blueprint-grid {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to right, rgba(6, 182, 212, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(6, 182, 212, 0.06) 1px, transparent 1px);
  background-size: 10px 10px, 10px 10px, 50px 50px, 50px 50px;
  pointer-events: none;
  z-index: 0;
}

/* App Structure */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(20, 24, 31, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-cad-main);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  margin-bottom: 16px;
}

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

.cad-logo-mark {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.cad-logo-mark svg {
  width: 100%;
  height: 100%;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-accent {
  color: var(--accent-amber);
}

.brand-subtitle {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-cyan);
  letter-spacing: 0.12em;
  margin-top: 2px;
}

.header-center {
  display: flex;
  gap: 10px;
}

.status-chip {
  background: var(--bg-cad-card);
  border: 1px solid var(--border-cad-dim);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.dot.live {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.badge-amber {
  background: rgba(245, 158, 11, 0.15);
  color: var(--text-amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-cyan {
  background: rgba(6, 182, 212, 0.15);
  color: var(--text-cyan);
  border: 1px solid rgba(6, 182, 212, 0.4);
}

.badge-green {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.mono {
  font-family: var(--font-mono);
}

/* Buttons */
.btn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent-amber);
  color: #0c0e12;
  font-weight: 700;
}

.btn-primary:hover {
  background: #fbbf24;
  box-shadow: 0 0 12px var(--accent-amber-glow);
}

.btn-outline {
  background: transparent;
  color: var(--text-cyan);
  border-color: var(--accent-cyan);
}

.btn-outline:hover {
  background: rgba(6, 182, 212, 0.1);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

/* Ribbon Tabs */
.nav-ribbon {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.nav-tab {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.nav-tab::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: all 0.2s ease;
}

.nav-tab:hover {
  background: var(--bg-cad-panel);
  border-color: var(--border-cad-main);
}

.nav-tab.active {
  background: var(--bg-cad-panel);
  border-color: var(--accent-amber);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.nav-tab.active::after {
  background: var(--accent-amber);
}

.tab-num {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.tab-label {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-top: 3px;
}

.tab-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Workbench Content */
.workbench-content {
  flex: 1;
  margin-bottom: 24px;
}

.module-pane {
  display: none;
  animation: fadeIn 0.2s ease;
}

.module-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CAD Panel Container */
.pane-grid {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 16px;
}

.cad-box {
  background: var(--bg-cad-panel);
  border: 1px solid var(--border-cad-main);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  position: relative;
}

.panel-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-cad-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(20, 24, 31, 0.5);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cad-decor {
  width: 6px;
  height: 6px;
  background: var(--accent-amber);
  display: inline-block;
  box-shadow: 0 0 6px var(--accent-amber);
}

.panel-body {
  padding: 18px;
}

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

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

.cad-select, .cad-input {
  width: 100%;
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-bright);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 9px 12px;
  font-size: 13px;
  transition: all 0.2s ease;
  outline: none;
}

.cad-select:focus, .cad-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan-glow);
}

.input-with-stepper {
  display: flex;
  align-items: center;
  position: relative;
}

.stepper-unit {
  position: absolute;
  right: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  pointer-events: none;
}

.radio-toggle {
  display: flex;
  gap: 8px;
}

.radio-label {
  flex: 1;
  position: relative;
  cursor: pointer;
}

.radio-label input {
  position: absolute;
  opacity: 0;
}

.radio-label span {
  display: block;
  text-align: center;
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s ease;
  color: var(--text-secondary);
}

.radio-label input:checked + span {
  background: var(--bg-cad-card);
  border-color: var(--accent-amber);
  color: #fff;
  box-shadow: 0 0 8px var(--accent-amber-glow);
}

.tech-note {
  background: rgba(6, 182, 212, 0.08);
  border-left: 3px solid var(--accent-cyan);
  padding: 10px 12px;
  font-size: 11px;
  color: #cbd5e1;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 14px;
}

.range-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* Metric Dashboard Cards */
.metric-dashboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  position: relative;
}

.metric-card.highlight {
  border-color: var(--accent-amber);
  background: linear-gradient(145deg, rgba(245, 158, 11, 0.08) 0%, var(--bg-cad-surface) 100%);
}

.metric-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.metric-card.highlight .metric-value {
  color: var(--text-amber);
}

.unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.metric-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* SVG Blueprint Viewport */
.draft-viewport {
  background: #090c10;
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 14px;
}

.draft-toolbar {
  background: #11151c;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-cad-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.scale-ind {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-size: 10px;
}

.svg-container {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
}

.recommendations-box {
  background: rgba(34, 41, 54, 0.5);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  color: #cbd5e1;
}

/* Materials Layout */
.materials-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
}

.search-box {
  margin-bottom: 12px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.chip-btn {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  background: var(--bg-cad-card);
  color: #fff;
}

.chip-btn.active {
  background: var(--accent-cyan);
  color: #0c0e12;
  font-weight: 700;
  border-color: var(--accent-cyan);
}

.materials-list {
  max-height: 580px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.mat-item {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
}

.mat-item:hover {
  background: var(--bg-cad-card);
  border-color: var(--border-cad-bright);
}

.mat-item.active {
  border-color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.08);
}

.mat-item-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.mat-item-type {
  font-size: 11px;
  color: var(--text-muted);
}

.mat-item-badge {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

/* Material Detail View */
.mat-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.spec-block {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.spec-block-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-cad-dim);
  padding-bottom: 4px;
}

.spec-prop-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
}

.spec-prop-row:last-child {
  margin-bottom: 0;
}

.spec-label {
  color: var(--text-secondary);
}

.spec-val {
  font-weight: 600;
  color: #fff;
  font-family: var(--font-mono);
}

.ht-section {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 18px;
}

.ht-section h3 {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-amber);
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  text-transform: uppercase;
}

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

.ht-table th, .ht-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-cad-dim);
}

.ht-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
}

.ht-table td {
  color: #e2e8f0;
}

.app-usages-box {
  background: rgba(6, 182, 212, 0.06);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.6;
}

/* Tolerances & Fits */
.fit-custom-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.fit-custom-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

.fit-divider {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-amber);
  margin-top: 18px;
}

.tolerance-chart-container {
  background: #090c10;
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* ESKD Tab */
.eskd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.roughness-selector {
  margin-bottom: 16px;
}

.roughness-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.r-pill {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.r-pill:hover {
  background: var(--bg-cad-card);
  color: #fff;
}

.r-pill.active {
  background: var(--accent-amber);
  color: #0c0e12;
  font-weight: 700;
  border-color: var(--accent-amber);
}

.roughness-card {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 16px;
}

.surface-micro-visualizer {
  background: #090c10;
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.surface-micro-visualizer canvas {
  width: 100%;
  height: 140px;
  display: block;
}

/* GD&T */
.gdt-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.gdt-symbols-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 4px;
}

.gdt-card {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: all 0.15s ease;
}

.gdt-card:hover {
  border-color: var(--border-cad-bright);
  background: var(--bg-cad-card);
}

.gdt-icon-box {
  width: 38px;
  height: 38px;
  background: #090c10;
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

.gdt-meta {
  flex: 1;
}

.gdt-meta-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 2px;
}

.gdt-meta-cat {
  font-size: 10px;
  color: var(--text-amber);
  text-transform: uppercase;
  font-weight: 600;
}

.gdt-meta-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

/* Weight Calculator */
.profile-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.profile-btn {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.profile-btn:hover {
  background: var(--bg-cad-card);
  color: #fff;
}

.profile-btn.active {
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--accent-amber);
  color: var(--text-amber);
}

.p-icon {
  font-size: 16px;
}

.actions-footer {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

/* Unit Converter Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-panel {
  width: 90%;
  max-width: 680px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-close-btn:hover {
  color: #fff;
}

.converter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.converter-card {
  background: var(--bg-cad-surface);
  border: 1px solid var(--border-cad-dim);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.converter-card h4 {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.conv-row:last-child {
  margin-bottom: 0;
}

.conv-row input {
  width: 140px;
}

.conv-label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Footer */
.app-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-cad-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: auto;
}

.text-success {
  color: var(--accent-green);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-cad-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--border-cad-main);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-cad-bright);
}

/* Responsive */
@media (max-width: 1024px) {
  .pane-grid, .materials-layout, .eskd-grid {
    grid-template-columns: 1fr;
  }
  .nav-ribbon {
    grid-template-columns: repeat(2, 1fr);
  }
  .metric-dashboard {
    grid-template-columns: 1fr;
  }
}
