/* ============================================================
   BOM Pricing System - Stylesheet
   Industrial / Utilitarian aesthetic
   ============================================================ */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-alt: #f9fafb;
    --border: #d1d5db;
    --border-light: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #059669;
    --success-light: #d1fae5;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0891b2;
    --info-light: #cffafe;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, monospace;
}

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

html { font-size: 15px; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Navigation ---- */
.main-nav {
    background: #1e293b;
    color: #e2e8f0;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.nav-inner {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 56px;
}
.nav-brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
}
.nav-brand:hover { text-decoration: none; color: #93c5fd; }
.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}
.nav-links a {
    color: #cbd5e1;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}
.user-badge {
    font-size: 0.82rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-weight: 500;
}
.role-admin { background: #7c3aed22; color: #a78bfa; border: 1px solid #7c3aed44; }
.role-engineer { background: #05966922; color: #6ee7b7; border: 1px solid #05966944; }
.role-viewer { background: #6b728022; color: #d1d5db; border: 1px solid #6b728044; }

/* ---- Container ---- */
.container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
    flex: 1;
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.page-header .actions { display: flex; gap: 0.5rem; }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    width: 100%;
}
.card-header {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-alt);
}
.card-body { padding: 1.25rem; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; width: 100%; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    table-layout: auto;
}
thead th {
    background: var(--surface-alt);
    border-bottom: 2px solid var(--border);
    padding: 0.6rem 0.85rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
}
tbody td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tbody tr:hover { background: #f0f4ff; }
td.mono { font-family: var(--font-mono); font-size: 0.85rem; }
td.num { text-align: right; font-family: var(--font-mono); font-size: 0.85rem; }
td.actions-cell { white-space: nowrap; }
td.actions-cell a { margin-right: 0.5rem; font-size: 0.85rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }
.btn-xs { padding: 0.15rem 0.45rem; font-size: 0.78rem; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.3rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 80px; resize: vertical; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.form-hint {
    font-size: 0.78rem;
    color: var(--text-light);
    margin-top: 0.2rem;
}
.form-inline { display: flex; gap: 0.5rem; align-items: end; }

/* Currency input group */
.currency-group {
    display: flex;
    gap: 0;
}
.currency-group .form-control:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    flex: 1;
}
.currency-group select.form-control {
    width: 90px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 0;
    background: var(--surface-alt);
}

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: var(--info-light); color: #155e75; border: 1px solid #67e8f9; }
.alert-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.6;
    color: inherit;
}

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-aud { background: #dbeafe; color: #1e40af; }
.badge-usd { background: #d1fae5; color: #065f46; }
.badge-cny { background: #fee2e2; color: #991b1b; }
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-obsolete { background: #fee2e2; color: #991b1b; }
.badge-internal { background: #dbeafe; color: #1e40af; }
.badge-outsourced { background: #fef3c7; color: #92400e; }

/* ---- Detail View ---- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.detail-field { }
.detail-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: 0.15rem;
}
.detail-value {
    font-size: 1rem;
    color: var(--text);
}
.detail-value.price {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.25rem;
}
.tab {
    padding: 0.6rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- Attachments ---- */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}
.file-card {
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
    font-size: 0.85rem;
    transition: box-shadow 0.15s;
}
.file-card:hover { box-shadow: var(--shadow-md); }
.file-card .icon { font-size: 2rem; margin-bottom: 0.3rem; }
.file-card .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-card .meta { color: var(--text-light); font-size: 0.78rem; }
.file-card img.thumb {
    max-width: 100%;
    max-height: 120px;
    border-radius: 4px;
    margin-bottom: 0.3rem;
}

/* ---- Notes ---- */
.note-item {
    border-left: 3px solid var(--primary);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background: var(--surface-alt);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.note-meta {
    font-size: 0.78rem;
    color: var(--text-light);
    margin-bottom: 0.3rem;
}
.note-content { white-space: pre-wrap; word-wrap: break-word; }
.note-actions { margin-top: 0.4rem; }

/* ---- BOM Tree ---- */
.bom-tree { list-style: none; }
.bom-tree .bom-tree { margin-left: 1.5rem; padding-left: 0.75rem; border-left: 2px solid var(--border-light); }
.bom-item {
    padding: 0.4rem 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.bom-item .type-tag {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    letter-spacing: 0.04em;
}
.type-part { background: #dbeafe; color: #1e40af; }
.type-process { background: #fef3c7; color: #92400e; }
.type-assembly { background: #ede9fe; color: #5b21b6; }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    padding: 1rem 0;
}
.pagination a, .pagination span {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.pagination a:hover { background: var(--surface-alt); text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Search / Filter bar ---- */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    align-items: end;
    width: 100%;
}
.filter-bar .form-control { width: auto; min-width: 160px; }
.filter-bar input[type="search"] { min-width: 250px; flex: 1; }

/* ---- Utility ---- */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ---- Footer ---- */
.main-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.82rem;
    color: var(--text-light);
    border-top: 1px solid var(--border-light);
    margin-top: auto;
}

/* ---- Login Page ---- */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}
.login-box {
    background: var(--surface);
    border-radius: 8px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-box h1 {
    font-size: 1.4rem;
    margin-bottom: 0.3rem;
}
.login-box p.sub {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* ---- Revision Diff ---- */
.diff-removed { background: #fee2e2; color: #991b1b; }
.diff-added { background: #d1fae5; color: #065f46; }
.rev-current { background: var(--primary-light); }
.rev-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.82rem;
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
    background: #e5e7eb;
    color: #374151;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .nav-inner { flex-wrap: wrap; height: auto; padding: 0.5rem 0; }
    .nav-links { order: 3; width: 100%; overflow-x: auto; }
    .form-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
}
