*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #c8c8c8; color: #1d1d1f; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 12px; user-select: none; -webkit-font-smoothing: antialiased; }

:root {
  --bg:      #ececec;
  --panel:   #f0f0f0;
  --panel2:  #e0e0e0;
  --panel3:  #fafafa;
  --accent:  #0052a3;
  --text:    #1a1a1a;
  --text2:   #555;
  --text3:   #888;
  --border:  #b0b0b0;
  --border2: #d0d0d0;
  --hover:   #d8e8f8;
  --active:  #c0d8f0;
  --sel:     rgba(0,82,163,.12);
  --red:     #cc2200;
  --green:   #228833;
  --orange:  #cc6600;
  --rbar:    264px;
  --sbar:    22px;
  --tline:   116px;
  /* CATIA color palette */
  --tb-bg:     #dcdcdc;
  --tb-border: #a0a0a0;
  --tb-row-h:  30px;
}

/* ═══════════════════════════════════════════════
   APP SHELL — Flex column
═══════════════════════════════════════════════ */
#app {
  display: flex; flex-direction: column;
  height: 100vh; width: 100vw; overflow: hidden;
}

/* ── MENU BAR ────────────────────────────────── */
#menubar {
  flex-shrink: 0; height: 26px;
  background: var(--tb-bg);
  border-bottom: 1px solid var(--tb-border);
  display: flex; align-items: center;
  padding: 0 4px; gap: 0; z-index: 300;
}
.mb-brand {
  font-size: 12px; font-weight: 700; color: var(--accent);
  padding: 0 10px 0 4px; letter-spacing: -.01em;
  border-right: 1px solid var(--border); margin-right: 4px; height: 100%;
  display: flex; align-items: center;
}
.mb-brand span { color: #cc4400; }
.menu-group { position: relative; }
.menu-btn {
  padding: 3px 10px; border: none; border-radius: 2px; background: transparent;
  color: var(--text); font-size: 11.5px; cursor: pointer; transition: background .1s; font-family: inherit; height: 26px;
}
.menu-btn:hover, .menu-btn.open-menu { background: var(--accent); color: #fff; }
.mb-right { margin-left: auto; display: flex; align-items: center; gap: 4px; height: 100%; padding: 0 4px; }
.mb-mode-btn {
  padding: 2px 10px; border: 1px solid transparent; border-radius: 2px; background: transparent;
  color: var(--text); font-size: 11px; cursor: pointer; transition: all .1s; font-family: inherit;
  display: flex; align-items: center; gap: 5px;
}
.mb-mode-btn:hover { background: var(--hover); border-color: var(--border); }
.mb-mode-btn.active { background: #fff; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.mb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 3px; }

/* ── TOOLBAR AREA ────────────────────────────── */
#toolbar-area {
  flex-shrink: 0;
  background: var(--tb-bg);
  border-bottom: 2px solid var(--tb-border);
}
.toolbar-row {
  display: flex; align-items: center; flex-wrap: nowrap;
  min-height: var(--tb-row-h); padding: 0 4px; gap: 0;
  border-bottom: 1px solid var(--border2);
  background: var(--tb-bg);
  overflow: visible;
  position: relative; z-index: 1;
}
.toolbar-row:last-child { border-bottom: none; }
#toolbar-area { overflow: visible; }
.tb-group {
  display: flex; align-items: center; gap: 1px;
  padding: 0 2px;
}
.tb-vsep {
  width: 1px; height: 20px; background: var(--tb-border);
  margin: 0 4px; flex-shrink: 0;
}
/* CATIA icon button */
.ti {
  width: 26px; height: 26px; border: 1px solid #c8c8c8; border-radius: 2px;
  background: #ebebeb; color: #2a2a2a; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all .08s; position: relative; flex-shrink: 0;
}
.ti:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.ti.active { background: var(--active); border-color: #0052a3; border-width: 1.5px; color: var(--accent); }
.ti.pressed { background: #b8d0e8; border-color: var(--accent); }

/* ── CATIA YELLOW TOOLTIP ───────────────────── */
.ti::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: #ffffcc;
  color: #000;
  border: 1px solid #808060;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  padding: 2px 7px;
  border-radius: 1px;
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  box-shadow: 2px 2px 4px rgba(0,0,0,.2);
  transition: opacity .12s;
}
.ti:hover::after { opacity: 1; }

/* Flyout arrow on tools with sub-tools */
.ti.has-sub::before {
  content: '';
  position: absolute; right: 1px; bottom: 1px;
  width: 0; height: 0;
  border-style: solid; border-width: 0 0 5px 5px;
  border-color: transparent transparent #666 transparent;
}

/* Fix z-index so top toolbar rows' tooltips render above lower rows */
#tb-standard { z-index: 12; }
#tb-view      { z-index: 11; }

/* ── WORKSPACE ───────────────────────────────── */
#workspace {
  flex: 1; display: grid;
  grid-template-columns: 36px 1fr auto var(--rbar);
  grid-template-rows: 1fr;
  overflow: hidden; min-height: 0;
}

/* ── RIGHT TOOLS (vertical CATIA columns) ────── */
#right-tools {
  background: var(--tb-bg);
  border-left: 1px solid var(--tb-border);
  display: flex; flex-direction: row; align-items: stretch;
  overflow: hidden;
}
.vtb-col {
  width: 32px; display: flex; flex-direction: column; align-items: center;
  padding: 3px 0; gap: 1px;
  border-right: 1px solid var(--border2);
  overflow-y: auto; overflow-x: hidden;
}
.vtb-col:last-child { border-right: none; }
.vtb-col::-webkit-scrollbar { width: 0; }
.vtb-sep { width: 22px; height: 1px; background: var(--border); margin: 2px auto; flex-shrink: 0; }
/* Disable CSS tooltip for right-tools (uses JS fixed tooltip instead) */
#right-tools .ti::after { display: none; }

/* ── LEFT PANEL (Nav only, like CATIA) ─────── */
#left-panel {
  background: var(--tb-bg);
  border-right: 1px solid var(--tb-border);
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 0; gap: 1px; overflow-y: auto; overflow-x: hidden;
}
.lp-sep { width: 24px; height: 1px; background: var(--border); margin: 3px auto; }
.lp-ti {
  width: 28px; height: 28px; border: 1px solid #c8c8c8; border-radius: 2px;
  background: #ebebeb; color: #2a2a2a; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all .08s; position: relative;
}
.lp-ti:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.lp-ti.active { background: var(--active); border-color: var(--accent); color: var(--accent); }
.lp-ti::after {
  content: attr(data-tip);
  position: absolute; left: 34px; top: 50%; transform: translateY(-50%);
  background: #ffffcc; color: #000; border: 1px solid #808060;
  font-size: 11px; padding: 2px 7px; white-space: nowrap; border-radius: 1px;
  z-index: 9999; pointer-events: none; opacity: 0; transition: opacity .12s;
  box-shadow: 2px 2px 4px rgba(0,0,0,.2);
}
.lp-ti:hover::after { opacity: 1; }

/* ── VIEWPORT ─────────────────────────────────── */
#viewport-container { position: relative; overflow: hidden; background: #808080; }
#viewport-2d, #viewport-3d { position: absolute; inset: 0; }
#viewport-3d { display: none; }
#canvas-2d { display: block; cursor: crosshair; background: #fff; }
#canvas-3d { display: block; }

/* View buttons overlay */
.view-buttons {
  position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 2px; z-index: 10;
}
.vb {
  padding: 3px 8px; background: rgba(230,230,230,.92); border: 1px solid #a0a0a0;
  border-radius: 2px; color: var(--text); font-size: 11px; cursor: pointer;
  font-family: inherit; transition: all .1s;
}
.vb:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }

/* Sketch info bar */
#sketch-info {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(240,240,240,.94); border: 1px solid #a0a0a0;
  border-radius: 2px; padding: 4px 10px; font-size: 11px; color: var(--text2);
  pointer-events: none; z-index: 10;
}

/* ── RIGHT PANEL ──────────────────────────────── */
#right-panel { background: var(--panel3); border-left: 1px solid var(--tb-border); display: flex; flex-direction: column; overflow: hidden; }
.rp-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--panel2); }
.rp-tab {
  flex: 1; padding: 6px 4px; border: none; background: transparent;
  color: var(--text3); font-size: 11px; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .1s; font-family: inherit;
}
.rp-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--panel3); }
.rp-tab:hover:not(.active) { color: var(--text2); }
.rp-content { flex: 1; overflow-y: auto; padding: 8px; display: none; }
.rp-content.active { display: block; }

/* Tree */
.tree-row { display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 3px; cursor: pointer; transition: background .08s; }
.tree-row:hover { background: var(--hover); }
.tree-row.selected { background: var(--sel); }
.tree-toggle { width: 12px; font-size: 9px; color: var(--text3); text-align: center; cursor: pointer; }
.tree-icon { font-size: 11px; width: 14px; text-align: center; }
.tree-label { flex: 1; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-vis { font-size: 10px; color: var(--text3); cursor: pointer; }
.tree-vis:hover { color: var(--text); }
.tree-children { padding-left: 12px; }
.tree-children.collapsed { display: none; }

/* Properties */
.prop-section { margin-bottom: 12px; }
.prop-title { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.prop-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.prop-label { width: 58px; color: var(--text2); font-size: 11px; flex-shrink: 0; }
.prop-input {
  flex: 1; background: #fff; border: 1px solid var(--border);
  border-radius: 2px; color: var(--text); font-size: 11px; padding: 3px 6px;
  font-family: inherit; outline: none;
}
.prop-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,82,163,.1); }
.prop-btn { width: 100%; padding: 5px; background: var(--panel2); border: 1px solid var(--border); border-radius: 2px; color: var(--text); font-size: 11px; cursor: pointer; margin-top: 3px; transition: all .1s; font-family: inherit; }
.prop-btn:hover { border-color: var(--accent); color: var(--accent); }
.prop-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.color-row { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px 0; }
.color-swatch { width: 20px; height: 20px; border-radius: 2px; cursor: pointer; border: 2px solid transparent; transition: all .1s; }
.color-swatch:hover, .color-swatch.active { border-color: var(--text); transform: scale(1.1); }

/* ── STATUS BAR ─────────────────────────────── */
#statusbar {
  flex-shrink: 0; height: var(--sbar);
  background: var(--tb-bg); border-top: 1px solid var(--tb-border);
  display: flex; align-items: center; padding: 0 10px; gap: 16px; font-size: 11px; color: var(--text3);
}
#statusbar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── TIMELINE (4D) ────────────────────────────── */
#timeline-bar {
  flex-shrink: 0; height: var(--tline);
  background: var(--panel); border-top: 1px solid var(--tb-border);
  display: none; flex-direction: column;
}
#timeline-bar.visible { display: flex; }
#timeline-controls { display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-bottom: 1px solid var(--border2); height: 30px; }
.tl-btn { width: 22px; height: 22px; border: none; background: transparent; color: var(--text2); font-size: 11px; cursor: pointer; border-radius: 2px; transition: all .1s; font-family: inherit; display: flex; align-items: center; justify-content: center; }
.tl-btn:hover { background: var(--hover); color: var(--text); }
.tl-btn.active { color: var(--accent); }
#timeline-time { font-size: 11px; color: var(--text2); min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
.tl-sep { width: 1px; height: 14px; background: var(--border2); margin: 0 2px; }
#timeline-tracks { flex: 1; overflow: hidden; display: flex; }
#track-labels { width: 120px; border-right: 1px solid var(--border2); overflow-y: auto; }
.track-label { height: 20px; display: flex; align-items: center; padding: 0 6px; font-size: 10px; color: var(--text2); border-bottom: 1px solid var(--border2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#track-area { flex: 1; overflow: hidden; position: relative; }
#track-canvas { display: block; }

/* ── DROPDOWN MENUS ─────────────────────────── */
.menu-group { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 0px); left: 0;
  background: #f4f4f4; border: 1px solid #909090;
  min-width: 220px; z-index: 500; padding: 2px;
  box-shadow: 3px 3px 8px rgba(0,0,0,.25); display: none;
}
.dropdown.open { display: block; }
.dropdown hr { border: none; border-top: 1px solid #c0c0c0; margin: 2px 0; }
.dd-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  cursor: pointer; transition: background .08s; font-size: 11.5px; color: var(--text);
}
.dd-item:hover { background: var(--accent); color: #fff; }
.dd-item:hover * { color: #fff !important; }
.dd-item .shortcut { margin-left: auto; color: var(--text3); font-size: 10.5px; }
.dd-item.danger { color: var(--red); }
.dd-item.danger:hover { background: var(--red); color: #fff; }
.dd-section-label { font-size: 10px; color: var(--text3); padding: 4px 10px 2px; text-transform: uppercase; letter-spacing: .05em; cursor: default; }
.dd-section-label:hover { background: transparent !important; }

/* ── CONTEXT MENU ────────────────────────────── */
#context-menu {
  position: fixed; background: #f4f4f4; border: 1px solid #909090;
  padding: 2px; min-width: 160px; z-index: 1000;
  box-shadow: 3px 3px 8px rgba(0,0,0,.25); display: none;
}
#context-menu.open { display: block; }
.cm-item { padding: 5px 12px; cursor: pointer; font-size: 11.5px; display: flex; align-items: center; gap: 8px; transition: background .08s; }
.cm-item:hover { background: var(--accent); color: #fff; }
.cm-item.danger { color: var(--red); }
#context-menu hr { border: none; border-top: 1px solid #c0c0c0; margin: 2px 0; }

/* ── NOTIFICATIONS ────────────────────────────── */
#notifications { position: fixed; bottom: 28px; right: 14px; z-index: 2000; display: flex; flex-direction: column; gap: 6px; }
.notif { padding: 8px 14px; border-radius: 2px; font-size: 11.5px; box-shadow: 2px 2px 8px rgba(0,0,0,.18); animation: slideIn .18s ease; max-width: 300px; font-family: inherit; border-left: 3px solid; }
.notif.success { background: #f0fff4; color: #1a5c2a; border-left-color: var(--green); border: 1px solid #b0d8b8; }
.notif.error   { background: #fff4f4; color: var(--red);   border-left-color: var(--red);   border: 1px solid #e8b0b0; }
.notif.info    { background: #f0f4ff; color: var(--accent); border-left-color: var(--accent); border: 1px solid #b0c8e8; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0 } to { transform: none; opacity: 1 } }

/* ── MODALS ──────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content {
  background: #f0f0f0; border: 2px solid #808080;
  border-radius: 2px; padding: 0; min-width: 340px;
  box-shadow: 4px 4px 12px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.modal-header {
  background: linear-gradient(180deg, #4080c0, #1060a0);
  color: #fff; padding: 6px 12px; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.modal-header i { font-size: 13px; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-content .prop-row { gap: 10px; }
.modal-content .prop-label { width: 110px; font-size: 12px; }
.modal-content input, .modal-content select {
  padding: 4px 8px; background: #fff; border: 1px solid #808080;
  border-radius: 1px; color: var(--text); font-family: inherit; font-size: 12px; outline: none;
}
.modal-content input:focus, .modal-content select:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 6px; justify-content: flex-end; padding: 8px 16px 14px; }
.modal-info { font-size: 11px; color: var(--text2); background: #fff; border: 1px solid #c0c8d0; padding: 8px 10px; border-radius: 1px; line-height: 1.5; }
.btn-sm { padding: 4px 18px; border: 1px solid #808080; border-radius: 1px; font-size: 12px; cursor: pointer; font-family: inherit; transition: all .1s; background: var(--tb-bg); color: var(--text); min-width: 70px; }
.btn-sm:hover { background: var(--hover); border-color: var(--accent); }
.btn-sm.primary { background: var(--accent); border-color: #003880; color: #fff; }
.btn-sm.primary:hover { background: #0064c8; }

/* ── SCROLLBARS (CATIA-like) ─────────────────── */
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: #d8d8d8; }
::-webkit-scrollbar-thumb { background: #a0a0a0; border: 2px solid #d8d8d8; border-radius: 1px; }
::-webkit-scrollbar-thumb:hover { background: #888; }
::-webkit-scrollbar-button { background: #c0c0c0; border: 1px solid #909090; height: 14px; width: 14px; }

/* ── TASK OVERLAY (establishment mode) ──────── */
#task-overlay {
  position: absolute; top: 10px; right: 10px; z-index: 200;
  background: rgba(255,255,255,.96); border: 1px solid var(--tb-border);
  border-radius: 4px; box-shadow: 2px 4px 16px rgba(0,0,0,.18);
  min-width: 220px; max-width: 280px; font-size: 11.5px;
}
#task-overlay-header {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px;
  background: linear-gradient(180deg,#4080c0,#1060a0); color:#fff; border-radius: 4px 4px 0 0;
  font-weight: 600; font-size: 11px;
}
#task-overlay-title { flex: 1; }
#task-overlay-toggle {
  background: none; border: none; color: #fff; cursor: pointer; font-size: 11px; padding: 0 2px;
}
#task-overlay-body { padding: 8px 10px; max-height: 240px; overflow-y: auto; }
#task-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
#task-list li { display: flex; align-items: flex-start; gap: 7px; cursor: pointer; }
#task-list li input[type=checkbox] { margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); }
#task-list li span { color: var(--text); line-height: 1.5; }
#task-list li.done span { text-decoration: line-through; color: var(--text3); }
#task-overlay.collapsed #task-overlay-body { display: none; }
#btn-submit-work { animation: pulse-blue 2.5s infinite; }
@keyframes pulse-blue {
  0%, 100% { box-shadow: 0 4px 20px rgba(37,99,235,.45); }
  50%       { box-shadow: 0 4px 28px rgba(37,99,235,.8); }
}

/* ── DISABLED TOOL (establishment restrictions) */
.ti.tool-disabled, .vtb-col .ti.tool-disabled {
  opacity: .3 !important; cursor: not-allowed !important; pointer-events: none !important;
}

/* ── FIXED TOOLTIP ──────────────────────────── */
#fixed-tip {
  position: fixed; z-index: 9999; pointer-events: none;
  background: #ffffcc; color: #000; border: 1px solid #808060;
  font-size: 11px; font-family: 'Inter', sans-serif; font-weight: 400;
  padding: 2px 7px; border-radius: 1px; white-space: nowrap;
  box-shadow: 2px 2px 4px rgba(0,0,0,.2);
  opacity: 0; transition: opacity .12s;
}
#fixed-tip.visible { opacity: 1; }

/* ── SAVE INDICATOR ──────────────────────────── */
.save-indicator { font-size: 11px; color: var(--text3); }
.save-indicator.saving { color: var(--orange); }
.save-indicator.saved  { color: var(--green); }
