/* app.css — KnitStitch Grid app overrides and app-specific styles
 *
 * Loads AFTER css/shared.css (served from the root Structured Chaos site).
 * Contains only:
 *   - Theme color overrides (KnitStitch uses a gold primary, not sage)
 *   - Layout overrides (scroll-margin-top, .panel border-radius)
 *   - Body-class active nav state
 *   - KnitStitch app layout (canvas, ribbon, workspace, floating panels,
 *     tool ribbon, object list, dimension overlay, color picker,
 *     small-screen warning, boot loading overlay)
 *
 * All tokens, base styles, typography, layout primitives, global bar,
 * site header, navigation, panels, chips, color pairs, buttons, forms,
 * lists, gallery, footer, and responsive breakpoints live in
 * css/shared.css.
 */

/* ==========================================================================
   1. Theme Overrides
   ========================================================================== */
:root {
    --primary: #ca9b52;
    --primary-light: #e4c78f;
    --primary-dark: #8b5d1f;
    --secondary: #f7f4ef;
    --secondary-light: #fbf9f5;
    --secondary-dark: #e8e2d8;
    --tertiary-dark: #f2eee8;
    --shadow-lg: 0 14px 28px rgba(26, 19, 9, 0.12);
}

[id] {
    scroll-margin-top: 116px;
}

/* ==========================================================================
   2. Active Nav (body-class driven — header is a shared include)
   ========================================================================== */
.page-home .main-nav-link[href="/"],
.page-readme .main-nav-link[href="/pages/readme.html"],
.page-roadmap .main-nav-link[href="/pages/roadmap.html"],
.page-changelog .main-nav-link[href="/pages/changelog.html"] {
    color: var(--primary);
}

/* ==========================================================================
   3. Panel Override
   ========================================================================== */
.panel {
    border-radius: 8px;
    overflow: hidden;
}

/* ==========================================================================
   4. KnitStitch App Layout
   ========================================================================== */

/* Flex layout for app-specific components (shared.css handles the common
   ones: .global-bar-row, .main-nav, .main-nav-item, .form-row, .checkbox-row,
   .slider-row, .page-subheader-inner, .footer-row) */
.ribbon-modes,
.zoom-control,
.canvas-content,
.ribbon-bar,
.object-list li,
.color-option,
.dim-edit-overlay__controls {
    display: flex;
    align-items: center;
}

.workspace-btn,
.zoom-btn {
    display: inline-flex;
    align-items: center;
}

.ribbon-bar,
.zoom-control {
    background: var(--tertiary);
    border: 1px solid var(--border);
}

.page-knitstitch,
.page-knitstitch > .shell,
#app-container,
.canvas-area,
#dim-edit-overlay,
.boot-loading-overlay {
    display: flex;
    flex-direction: column;
}

/* Full-height layout — page never scrolls, only sidebar/canvas scroll internally */
.page-knitstitch {
    height: 100vh;
    overflow: hidden;
}

.page-knitstitch .global-bar,
.page-knitstitch .site-header,
.page-knitstitch .site-footer {
    flex-shrink: 0;
}

.page-knitstitch .global-bar,
.page-knitstitch .site-header {
    z-index: 10001;
}

.page-knitstitch .site-footer {
  padding: 4px 0;
  background: var(--secondary-dark);
  border-top: 1px solid var(--border);
}

.page-knitstitch > .shell {
  flex: 1;
  min-height: 0;
  padding: 0;
  width: 100%;
  margin: 0;
}

.editor-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
    overflow: hidden;
    background: transparent;
    box-shadow: none;
}

#app-container {
    flex: 1;
    min-height: 0;
}

/* Ribbon bar */
.ribbon-bar {
    justify-content: center;
    border-radius: 0;
    margin: 0;
    padding: 8px 12px;
    gap: 8px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--secondary-dark);
}

.ribbon-modes {
    gap: 8px;
    flex-wrap: nowrap;
}

.workspace-btn,
.zoom-btn {
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
}

.workspace-btn {
    flex: 0 0 auto;
    padding: 6px 14px;
    border-radius: 6px;
    gap: 6px;
    white-space: nowrap;
    position: relative;
}

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

.workspace-btn .icon {
    font-size: 18px;
    color: var(--body);
    line-height: 1;
}

.workspace-btn .label {
    font-size: 10px;
    color: var(--body);
    line-height: 1;
}

.workspace-btn.active {
    background: var(--color-pair-gold-bg);
}

.workspace-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

/* Workspace layout: vertical tabs on the left, canvas filling the rest */
.workspace-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
}

.ribbon-bar--workspace {
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  width: var(--sidebar-width, 320px);
  min-width: 180px;
  max-width: 600px;
  padding: 0;
  gap: 0;
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: none;
  box-shadow: none;
  background: var(--secondary);
  overflow: hidden;
  position: relative;
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 250;
  background: transparent;
  transition: box-shadow 0.1s;
  touch-action: none;
}

.sidebar-resizer:hover,
.sidebar-resizer.is-active {
  background: transparent;
  box-shadow: inset -1px 0 0 0 var(--primary-dark), 1px 0 4px rgba(0,0,0,0.25);
}

.ribbon-bar--workspace .ribbon-modes {
  flex-direction: row;
  flex-shrink: 0;
  gap: 2px;
  padding: 4px;
  border-bottom: 1px solid var(--border);
}

.ribbon-bar--workspace .workspace-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 2px;
  border-radius: 5px;
  gap: 2px;
  flex: 1;
  white-space: normal;
  text-align: center;
  font-size: 10px;
}

.ribbon-bar--workspace .workspace-btn .icon {
  font-size: 14px;
}

.ribbon-bar--workspace .workspace-btn .label {
  font-size: 8px;
  line-height: 1.1;
}

.ribbon-bar--workspace .workspace-btn.active {
  background: var(--color-pair-gold-bg);
}

.left-accordion-section {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.left-accordion-section.active {
  display: flex;
}

.left-accordion-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.left-accordion-body .container-section--headed {
  flex-shrink: 0;
}

.left-accordion-body .container-section-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: 12px;
}

.left-accordion-body .container-section-header::after {
  content: '▾';
  font-size: 11px;
  color: var(--body-light);
  transition: transform 0.15s;
}

.left-accordion-body .container-section--headed.is-collapsed .container-section-header::after {
  transform: rotate(-90deg);
}

.left-accordion-body .container-section--headed.is-collapsed .container-section-body {
  display: none;
}

.left-accordion-body .container-section-body .form-row,
.left-accordion-body .container-section-body .checkbox-row,
.left-accordion-body .container-section-body .slider-row {
  gap: 6px;
}

/* Canvas area — fills the remaining width of the workspace layout */
.workspace-layout .canvas-area--full {
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.canvas-area {
    min-width: 0;
    position: relative;
}

.canvas-wrapper {
  flex: 1;
  border-radius: 0;
  overflow: auto;
  padding: 0;
  border: none;
  background: var(--tertiary);
}

.canvas-content {
  flex: 1;
  min-height: 0;
  justify-content: center;
  background: var(--tertiary);
}

/* Floating zoom control */
.zoom-control {
    position: absolute;
    top: 12px;
    left: 12px;
    gap: 2px;
    padding: 4px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(26, 19, 9, 0.12);
    z-index: 100;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    justify-content: center;
    border-radius: 5px;
    color: var(--body);
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

.zoom-btn:hover {
    background: var(--secondary-light);
    border-color: var(--border);
}

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

.zoom-level {
    min-width: 42px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--body);
    user-select: none;
}

.zoom-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 2px;
}

/* ==========================================================================
   Tool ribbon — contextual toolbar below the workspace ribbon (Fusion 360 style)
   ========================================================================== */
.ribbon-bar--tools {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  flex-wrap: nowrap;
  justify-content: center;
  border-radius: 0;
  margin: 0;
  padding: 6px 12px;
  gap: 0;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  overflow-x: auto;
  background: var(--secondary-dark);
  border-bottom: 1px solid var(--border);
  z-index: 150;
}

.ribbon-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
}

.ribbon-group-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--body-light);
    user-select: none;
}

.ribbon-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.ribbon-buttons--settings {
    gap: 6px;
}

.ribbon-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    margin: 2px 4px;
}

/* Tool buttons — icon + text, compact */
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 44px;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
    font-size: 11px;
    color: var(--body);
    transition: background 0.12s ease, border-color 0.12s ease;
}

.tool-btn:hover {
    background: var(--secondary-light);
    border-color: var(--border);
}

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

.tool-btn.button-primary,
.tool-btn.is-active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-dark);
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tool-btn--sm {
    min-width: 36px;
    padding: 4px 4px;
}

.tool-icon {
    font-size: 16px;
    line-height: 1;
    width: 100%;
    text-align: center;
}

.tool-label {
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
}

/* Compact form controls in the ribbon */
.ribbon-select {
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    background: var(--tertiary);
    color: var(--body);
}

.ribbon-slider-label {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ribbon-slider {
    width: 60px;
}

.ribbon-checkbox {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    cursor: pointer;
    user-select: none;
}

.ribbon-checkbox input {
    margin: 0;
}

.ribbon-status {
    font-size: 11px;
    color: #c0392b;
    align-self: center;
    white-space: nowrap;
}

/* ==========================================================================
   Floating panels — workspace-specific content overlaying the canvas
   ========================================================================== */
.floating-panel {
  position: absolute;
  top: 0;
  left: var(--sidebar-width, 240px);
  width: var(--floating-panel-width, 300px);
  height: 100%;
  display: none;
  flex-direction: column;
  background: var(--tertiary);
  border-right: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  z-index: 200;
  overflow: hidden;
}

.floating-panel-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 201;
  background: transparent;
  border-radius: 0 8px 8px 0;
}

.floating-panel-resizer:hover,
.floating-panel-resizer.is-active {
    background: var(--primary-light);
}

.floating-panel.active {
    display: flex;
}

.floating-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--tertiary-dark);
    cursor: pointer;
    user-select: none;
}

.floating-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--body);
}

.floating-panel-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--body-light);
    padding: 0;
    line-height: 1;
}

.floating-panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
}

.floating-panel.collapsed .floating-panel-body {
    display: none;
}

.floating-panel.collapsed .floating-panel-toggle {
    transform: rotate(-90deg);
}

.floating-panel-body > .container-section--headed + .container-section--headed {
    margin-top: 14px;
}

/* Measurement derived-values list */
.measurement-derived {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
    font-size: var(--type-caption);
    color: var(--body-light);
    line-height: 1.6;
}

.measurement-derived li {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.measurement-derived span {
    font-weight: 600;
    color: var(--primary-dark);
}

/* Workspace panels are now floating panels (see .floating-panel rules).
   The .workspace-panel class is retained for active/inactive toggling. */
.workspace-panel {
    display: none;
}

/* Object list */
.object-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

.object-list li {
    gap: 6px;
    padding: 3px 4px;
    font-size: 12px;
    border-radius: 3px;
}

.object-list li::before {
    content: none;
}

.object-list li:hover { background: var(--tertiary-dark); }

.object-list li.is-selectable {
    cursor: pointer;
}

.object-list li.selected {
    background: var(--color-pair-gold-bg);
    color: var(--primary-dark);
    font-weight: 600;
}

/* Row counts list styling (panel is now a floating panel) */
#panel-row-counts #row-counts-list {
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
}

#panel-row-counts #row-counts-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

#panel-row-counts #row-counts-list .row-label {
    font-weight: 600;
}

#panel-row-counts #row-counts-list .row-count {
    font-size: 11px;
    color: var(--body-light);
}

#panel-row-counts #row-counts-list .row-instruction {
    font-size: 11px;
    color: var(--body);
}

/* Dimension edit overlay */
#dim-edit-overlay {
    position: fixed;
    z-index: 9999;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    background: var(--tertiary) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12) !important;
    color: var(--body) !important;
}

#dim-edit-overlay .dim-edit-overlay__label,
#dim-edit-overlay .dim-edit-overlay__hint {
    font-size: 11px;
    color: var(--body-light);
}

#dim-edit-overlay .dim-edit-overlay__controls {
    gap: 6px;
}

#dim-edit-overlay .dim-edit-overlay__input {
    width: 72px;
    padding: 2px 4px;
    font-size: 12px;
    background: var(--tertiary) !important;
    color: var(--body) !important;
    border: 1px solid var(--border) !important;
    border-radius: 3px !important;
    font-family: inherit;
}

#dim-edit-overlay .dim-edit-overlay__button {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 3px !important;
    cursor: pointer;
    font-weight: 700;
    background: var(--secondary-dark) !important;
    color: var(--primary-dark) !important;
}

#dim-edit-overlay .dim-edit-overlay__button--primary {
    background: var(--primary) !important;
    color: white !important;
}

/* Import pattern chooser overlay */
.sketch-import-chooser {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
}

.sketch-import-chooser__panel {
    max-width: 380px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--tertiary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    color: var(--body);
}

.sketch-import-chooser__title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sketch-import-chooser__hint {
    font-size: 12px;
    color: var(--body-light);
    line-height: 1.4;
    margin-bottom: 14px;
}

.sketch-import-chooser__controls {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.sketch-import-chooser__button--replace {
    background: var(--primary) !important;
    color: white !important;
}

.sketch-import-chooser__button--merge {
    background: var(--secondary-dark) !important;
    color: var(--primary-dark) !important;
}

/* Color picker */
.color-option {
    gap: 6px;
}

.color-swatch {
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 2px;
}

/* ==========================================================================
   Site Footer additions
   ========================================================================== */
.footer-finished-size {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==========================================================================
   Small-screen warning page
   ========================================================================== */
.small-screen-warning {
    display: flex;
    align-items: center;
}

.small-screen-warning__panel {
    max-width: 680px;
    margin: 0 auto;
    padding: clamp(28px, 6vw, 60px);
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--secondary-light);
    box-shadow: var(--shadow-md);
    text-align: center;
}

.small-screen-warning__eyebrow {
    margin-bottom: 10px;
    color: var(--primary-dark);
    font-size: var(--type-caption);
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.small-screen-warning__panel h1 {
    margin-bottom: 18px;
}

.small-screen-warning__message {
    color: var(--body-dark);
    font-size: 16px;
}

.small-screen-warning__panel .button {
    margin-top: 10px;
}

/* ==========================================================================
   Boot loading overlay
   ========================================================================== */
.boot-loading-overlay {
    position: fixed;
    inset: 0;
    top: var(--boot-loading-overlay-top, 109px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: var(--tertiary);
    transition: opacity 0.2s ease;
}

.boot-loading-overlay.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.boot-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--secondary-dark);
    border-top-color: var(--primary-dark);
    border-radius: 50%;
    animation: boot-loading-spin 0.8s linear infinite;
}

.boot-loading-text {
    font-family: var(--font-body);
    font-size: var(--type-subtitle);
    color: var(--body-light);
    margin: 0;
}

@keyframes boot-loading-spin {
    to { transform: rotate(360deg); }
}
