/* Framed IN — Trade UI */
:root {
    --bg: #f5f4f1;
    --surface: #ffffff;
    --border: #e2e0db;
    --text: #1a1a18;
    --muted: #6b6b66;
    --accent: #2d4a3e;
    --accent-light: #3d6354;
    --accent-bg: #e8f0ec;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --success: #166534;
    --success-bg: #dcfce7;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --nav-h: 56px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* Layout */
.app-header {
    background: var(--accent);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    height: var(--nav-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.brand span { opacity: .7; font-weight: 400; }

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: .25rem;
}

.main-nav {
    display: flex;
    gap: .25rem;
    align-items: center;
}

.main-nav a {
    color: rgba(255,255,255,.85);
    padding: .4rem .75rem;
    border-radius: var(--radius);
    font-size: .9rem;
    text-decoration: none;
    white-space: nowrap;
}

.main-nav a:hover,
.main-nav a.active {
    background: rgba(255,255,255,.15);
    color: #fff;
    text-decoration: none;
}

.user-menu {
    position: relative;
    font-size: .85rem;
    white-space: nowrap;
}

.user-menu-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,.85);
    font-family: inherit;
    font-size: .85rem;
    cursor: pointer;
    padding: .4rem .5rem;
    border-radius: var(--radius);
}

.user-menu-toggle:hover,
.user-menu-toggle[aria-expanded="true"] {
    background: rgba(255,255,255,.15);
    color: #fff;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + .35rem);
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    z-index: 110;
    overflow: hidden;
}

.user-menu-dropdown.open {
    display: block;
}

.user-menu-dropdown a {
    display: block;
    padding: .6rem .85rem;
    color: var(--text);
    font-size: .9rem;
    text-decoration: none;
}

.user-menu-dropdown a:hover {
    background: var(--accent-bg);
    text-decoration: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2rem;
}

.page-title {
    margin: 0 0 1.25rem;
    font-size: 1.5rem;
    font-weight: 600;
}

.page-subtitle {
    margin: -.75rem 0 1.25rem;
    color: var(--muted);
    font-size: .95rem;
}

/* Cards & grids */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card h2, .card h3 {
    margin: 0 0 .75rem;
    font-size: 1rem;
    font-weight: 600;
}

.stat-card {
    text-align: center;
    padding: 1rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.stat-label {
    font-size: .8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* Forms */
.form-group { margin-bottom: 1rem; }

label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: .35rem;
    color: var(--text);
}

.label-hint {
    font-weight: 400;
    color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

textarea { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
}

.form-inline {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
}

.form-inline .form-group { flex: 1; margin-bottom: 0; }

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .9rem;
    cursor: pointer;
}

.checkbox-item input { width: auto; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
    transition: background .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); text-decoration: none; color: #fff; }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }

.btn-sm { padding: .35rem .75rem; font-size: .85rem; }

.btn-block { width: 100%; }

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

/* Tables */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

th, td {
    padding: .6rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    background: var(--bg);
}

tr:hover td { background: var(--accent-bg); }

/* Badges */
.badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.badge-approved { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-ready { background: var(--success-bg); color: var(--success); }
.badge-collected { background: #e5e7eb; color: #374151; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-draft { background: #f3f4f6; color: #6b7280; }
.badge-sent { background: #dbeafe; color: #1e40af; }

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}

.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #fde68a; }
.alert-info { background: var(--accent-bg); color: var(--accent); border: 1px solid #b8d4c8; }

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--accent);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.login-card h1 {
    margin: 0 0 .25rem;
    font-size: 1.5rem;
    text-align: center;
}

.login-card .subtitle {
    text-align: center;
    color: var(--muted);
    margin-bottom: 1.5rem;
    font-size: .9rem;
}

/* Job board */
.kanban {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: start;
}

@media (max-width: 900px) {
    .kanban { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
    .kanban { grid-template-columns: 1fr; }
}

.kanban-col {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 200px;
}

.kanban-header {
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-count {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .1rem .5rem;
    font-size: .75rem;
}

.kanban-cards { padding: .5rem; }

.job-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem;
    margin-bottom: .5rem;
    cursor: pointer;
    transition: box-shadow .15s;
}

.job-card:hover { box-shadow: var(--shadow); }

.job-card .job-num { font-weight: 600; font-size: .85rem; }
.job-card .job-customer { font-size: .9rem; margin: .25rem 0; }
.job-card .job-meta { font-size: .8rem; color: var(--muted); }

/* Quote builder */
.quote-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 900px) {
    .quote-layout { grid-template-columns: 1fr; }
}

.price-panel {
    position: sticky;
    top: calc(var(--nav-h) + 1rem);
}

.price-breakdown { font-size: .9rem; }

.price-line {
    display: flex;
    justify-content: space-between;
    padding: .35rem 0;
    border-bottom: 1px solid var(--border);
}

.price-line.total {
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: none;
    padding-top: .5rem;
    color: var(--accent);
}

.price-line.deposit {
    color: var(--muted);
    font-size: .85rem;
}

.turnaround {
    background: var(--accent-bg);
    padding: .75rem;
    border-radius: var(--radius);
    font-size: .9rem;
    margin: .75rem 0;
    text-align: center;
}

.scan-field {
    position: relative;
}

.scan-field input { padding-right: 2.5rem; }

.scan-icon {
    position: absolute;
    right: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 1.1rem;
    pointer-events: none;
}

/* Job detail modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    margin: 2rem auto;
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 { margin: 0; font-size: 1.15rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
}

.modal-body { padding: 1.25rem; }

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
    margin-bottom: 1rem;
    font-size: .9rem;
}

.detail-item label { font-size: .75rem; color: var(--muted); margin-bottom: .15rem; }
.detail-item span { font-weight: 500; }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: .5rem;
    margin-top: .5rem;
}

.photo-thumb {
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
}

.photo-upload {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s;
}

.photo-upload:hover { border-color: var(--accent); }

.photo-upload input { display: none; }

/* Stock indicators */
.stock-low { color: var(--danger); font-weight: 600; }
.stock-ok { color: var(--success); }

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--muted);
    font-size: .9rem;
}

/* Mobile nav */
@media (max-width: 768px) {
    .nav-toggle { display: block; }

    .main-nav {
        display: none;
        position: absolute;
        top: var(--nav-h);
        left: 0;
        right: 0;
        background: var(--accent);
        flex-direction: column;
        padding: .5rem;
        border-top: 1px solid rgba(255,255,255,.1);
    }

    .main-nav.open { display: flex; }

    .main-nav a { width: 100%; padding: .75rem 1rem; }
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
    overflow-x: auto;
}

.tab {
    padding: .6rem 1rem;
    border: none;
    background: none;
    font-size: .9rem;
    font-family: inherit;
    cursor: pointer;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hidden { display: none !important; }
