/* Nester — Water Jet Cutting Nesting Tool */

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

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface-2: #0f3460;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --text: #eee;
    --text-dim: #999;
    --border: #333;
    --success: #4caf50;
    --warning: #ff9800;
    --sheet-fill: #1a2744;
    --sheet-stroke: #4a90d9;
    --part-fill: rgba(76, 175, 80, 0.3);
    --part-stroke: #4caf50;
    --part-hover: rgba(233, 69, 96, 0.4);
    --grid-line: rgba(255, 255, 255, 0.06);
    --grid-line-major: rgba(255, 255, 255, 0.12);
}

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

/* ── Header ───────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
    flex-shrink: 0;
}

header h1 span {
    color: var(--accent);
}

.header-stats {
    display: flex;
    gap: 20px;
    font-size: 13px;
    flex-shrink: 0;
}

.stat-label {
    color: var(--text-dim);
    margin-right: 4px;
}

.stat-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ── Project selector ────────────────────── */

.project-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    max-width: 400px;
}

.project-selector select {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

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

.project-selector .btn-sm {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

/* ── Main layout ──────────────────────────── */

.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────── */

.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

/* ── Buttons ──────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

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

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 6px;
}

/* ── Inputs ───────────────────────────────── */

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

.input-row label {
    font-size: 12px;
    color: var(--text-dim);
    min-width: 60px;
}

.input-row input[type="number"],
.input-row input[type="text"] {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    width: 0;
}

.input-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-row .unit {
    font-size: 11px;
    color: var(--text-dim);
}

.input-row input[type="color"] {
    width: 36px;
    height: 28px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    flex: 0 0 auto;
}

.input-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.input-row input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

/* ── Part list ────────────────────────────── */

.part-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.part-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    background: var(--bg);
    cursor: default;
}

.part-item:hover {
    background: var(--surface-2);
}

.part-thumb {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.part-thumb svg {
    width: 100%;
    height: 100%;
}

.part-info {
    flex: 1;
    min-width: 0;
}

.part-name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.part-dims {
    font-size: 10px;
    color: var(--text-dim);
}

.material-select {
    margin-top: 3px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    color: var(--text);
    font-size: 10px;
    width: 100%;
    cursor: pointer;
}

.material-select:focus {
    outline: none;
    border-color: var(--accent);
}

.part-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.qty-input {
    width: 36px;
    padding: 2px 4px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
}

.btn-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    line-height: 1;
}

.btn-delete:hover {
    color: var(--accent);
}

/* ── Sheet list ──────────────────────────── */

.sheet-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.sheet-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    background: var(--bg);
    cursor: default;
}

.sheet-item:hover {
    background: var(--surface-2);
}

.sheet-color-picker {
    width: 28px;
    height: 28px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    flex-shrink: 0;
}

.sheet-color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.sheet-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.sheet-item-info {
    flex: 1;
    min-width: 0;
}

.sheet-item-name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-item-dims {
    font-size: 10px;
    color: var(--text-dim);
}

.sheet-item-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.add-sheet-form {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

/* ── Sheet tabs ──────────────────────────── */

.sheet-tabs {
    display: none;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px;
}

.sheet-tabs.visible {
    display: flex;
}

.sheet-tab {
    padding: 5px 14px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: none;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.sheet-tab:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sheet-tab.active {
    background: var(--accent);
    color: var(--text);
    border-color: var(--accent);
}

/* ── Canvas area ──────────────────────────── */

.canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}

.canvas-area svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ── SVG element styles ───────────────────── */

.sheet-outline {
    fill: var(--sheet-fill);
    stroke: var(--sheet-stroke);
    stroke-width: 0.02;
}

.part-shape {
    fill: var(--part-fill);
    stroke: var(--part-stroke);
    stroke-width: 0.015;
    fill-rule: evenodd;
    cursor: grab;
    transition: fill 0.1s;
}

.part-shape:hover {
    fill: var(--part-hover);
}

.part-shape.dragging {
    cursor: grabbing;
    stroke: var(--accent);
    stroke-width: 0.025;
    fill: rgba(233, 69, 96, 0.3);
}

.part-shape.collision {
    stroke: #ff0000;
    stroke-width: 0.03;
    fill: rgba(255, 0, 0, 0.2);
}

.part-shape.unplaced {
    fill: rgba(255, 152, 0, 0.2);
    stroke: var(--warning);
    stroke-dasharray: 0.05 0.03;
}

.grid-line {
    stroke: var(--grid-line);
    stroke-width: 0.005;
}

.grid-line-major {
    stroke: var(--grid-line-major);
    stroke-width: 0.008;
}

.ruler-text {
    fill: var(--text-dim);
    font-size: 0.2px;
    font-family: monospace;
}

/* ── Status bar ───────────────────────────── */

.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ── Loading/toast ────────────────────────── */

.toast {
    position: fixed;
    bottom: 40px;
    right: 16px;
    padding: 10px 20px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    z-index: 100;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-color: var(--accent);
}

/* ── Drop zone ────────────────────────────── */

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 6px;
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    color: var(--text);
    background: rgba(233, 69, 96, 0.05);
}

.drop-zone input[type="file"] {
    display: none;
}

/* ── Scrollbar ────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}
