/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* === Nav === */
.top-nav {
    background: var(--text);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    color: white;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}
.save-status {
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.15);
}
.save-status-saved { color: #86efac; }
.save-status-saving { color: #fde68a; }
.save-status-error { color: #fca5a5; }
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-logout {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 4px;
}
.nav-logout:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

/* === Container === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    min-height: 44px;
    touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 36px; }
.btn-add {
    width: 100%;
    padding: 14px;
    border: 2px dashed var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 48px;
    transition: border-color 0.15s, color 0.15s;
}
.btn-add:hover { border-color: var(--primary); color: var(--primary); }

/* === Forms === */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-group input, .form-group select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    min-height: 40px;
    width: 100%;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.form-group-inline { flex-direction: row; align-items: center; gap: 8px; }
.form-group-inline label { white-space: nowrap; }
.form-group-inline input { width: 80px; }
.input-lg { font-size: 1.1rem; padding: 10px 12px; }
.input-sm { width: 80px; }
input[type="number"] { font-variant-numeric: tabular-nums; }

/* === Dashboard === */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.dashboard-header h1 { font-size: 1.5rem; }
.project-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    position: relative;
    transition: box-shadow 0.15s;
}
.project-card:hover { box-shadow: var(--shadow-lg); }
.project-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}
.project-card h3 { font-size: 1.1rem; margin-bottom: 4px; }
.project-address { color: var(--text-muted); font-size: 0.9rem; }
.project-date { color: var(--text-muted); font-size: 0.8rem; margin-top: 8px; }
.project-delete {
    position: absolute;
    top: 12px;
    right: 12px;
}
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1.1rem;
    grid-column: 1 / -1;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}
.modal h2 { margin-bottom: 16px; }
.modal .form-group { margin-bottom: 14px; }
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* === Editor === */
.project-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.project-header-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 12px;
}
.project-settings {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* === Tabs === */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 12px 20px;
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    min-height: 44px;
    transition: color 0.15s, border-color 0.15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Fixture Rows === */
.fixture-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.fixture-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.fixture-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    min-height: 48px;
    transition: background 0.1s;
}
.fixture-summary:hover { background: #f1f5f9; }
.fixture-summary:active { background: #e2e8f0; }

.fixture-id-display {
    font-weight: 700;
    font-size: 0.95rem;
    min-width: 40px;
    color: var(--primary);
}
.fixture-desc-display {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fixture-qty-display {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.status-dots {
    display: flex;
    gap: 4px;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d1d5db;
    transition: background-color 0.2s;
}
.expand-icon {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.fixture-row.expanded .expand-icon { transform: rotate(180deg); }

/* === Fixture Detail (Expandable) === */
.fixture-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}
.fixture-row.expanded .fixture-detail {
    max-height: 2000px;
    transition: max-height 0.4s ease-in;
}

.detail-grid {
    padding: 0 16px 16px;
}
.detail-section {
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
.detail-section:first-child { border-top: none; }
.detail-section h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 8px;
}
.field-row:last-child { margin-bottom: 0; }

.fixture-actions {
    padding: 0 16px 16px;
    display: flex;
    justify-content: flex-end;
}

/* === Status select coloring === */
.status-select { font-size: 0.85rem; }

/* === Locked fields === */
.field-locked {
    background: #f1f5f9 !important;
    color: #94a3b8 !important;
    cursor: not-allowed;
    border-color: #e2e8f0 !important;
}

/* === Approved date display === */
.approved-date-display {
    font-size: 0.7rem;
    font-weight: 400;
    color: #9333ea;
    text-transform: none;
    letter-spacing: normal;
    margin-left: 6px;
}

/* === Color Picker === */
.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s, border-color 0.15s;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text); }
.color-swatch[data-color="white"] {
    border: 2px solid var(--border);
}
.color-swatch-none {
    border: 2px dashed var(--border);
    position: relative;
}
.color-swatch-none::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 2px;
    right: 2px;
    height: 1px;
    background: var(--text-muted);
    transform: rotate(-45deg);
}

/* === Report Bar === */
.report-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 24px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.report-label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-right: 4px;
}

/* === Tablet (600px+) === */
@media (min-width: 600px) {
    .project-grid { grid-template-columns: 1fr 1fr; }
    .project-header-fields { grid-template-columns: 1fr 1fr; }
    .field-row { grid-template-columns: repeat(2, 1fr); }
    .field-row .form-group-wide { grid-column: span 2; }
}

/* === Desktop (1024px+) === */
@media (min-width: 1024px) {
    .project-grid { grid-template-columns: 1fr 1fr 1fr; }
    .field-row { grid-template-columns: repeat(4, 1fr); }
    .field-row .form-group-wide { grid-column: span 2; }
    .container { padding: 24px; }
}

/* === Print styles === */
@media print {
    .top-nav, .tab-bar, .btn-add, .fixture-actions, .report-bar,
    .project-settings, .save-status, .btn { display: none !important; }

    body { background: white; font-size: 10pt; }
    .container { max-width: none; padding: 0; }
    .project-header { box-shadow: none; border: none; padding: 0; margin-bottom: 8pt; }
    .fixture-row { box-shadow: none; page-break-inside: avoid; }
    .fixture-detail { max-height: none !important; overflow: visible !important; }
}
