/* ===== Variables ===== */
:root {
    --primary: #1e293b;
    --primary-hover: #334155;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-focus: #94a3b8;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ===== Global ===== */
body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
    font-size: 0.9rem;
    line-height: 1.6;
}

.mono {
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
    font-size: 1em;
    background-color: #f1f5f9;
    color: #d63384;
    padding: 2px 6px;
    border-radius: 4px;
}

/* ===== Navbar ===== */
.navbar-app {
    background: var(--primary);
    padding: 0;
}

.navbar-app .navbar-brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
    color: #fff !important;
    padding: 0.75rem 0;
}

.navbar-app .nav-link {
    color: rgba(255,255,255,0.65) !important;
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.75rem 1rem !important;
    transition: color 0.15s;
}

.navbar-app .nav-link:hover,
.navbar-app .nav-link.active {
    color: #fff !important;
}

/* ===== Page Header ===== */
.page-header {
    padding: 1.5rem 0 0.5rem;
    margin-bottom: 0.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.02em;
}

/* ===== Section Groups ===== */
.section-group {
    margin-bottom: 2rem;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ===== Section Rows ===== */
.section-row {
    display: grid;
    gap: 1rem;
}

.section-row--3 {
    grid-template-columns: repeat(3, 1fr);
}

.section-row--2 {
    grid-template-columns: repeat(2, 1fr);
}

.section-row--1 {
    grid-template-columns: 1fr;
    max-width: 680px;
}

@media (max-width: 992px) {
    .section-row--3 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .section-row--3 {
        grid-template-columns: 1fr;
    }
    .section-row--2 {
        grid-template-columns: 1fr;
    }
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card--product-form {
    overflow: visible;
}

.card-header-custom {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.card-header-custom h2 {
    font-size: 0.75rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-body-custom {
    padding: 1rem;
}

.card-body-custom--table {
    padding: 0;
    overflow-x: auto;
}

.card--items {
    min-height: 200px;
}

/* ===== Inline Product Row ===== */
.product-inline-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-wrap: nowrap;
    position: relative;
    z-index: 10;
}

.product-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.product-field--barcode {
    flex: 1.4;
    position: relative;
}

.product-field--name {
    flex: 2;
}

.product-field--unit {
    flex: 0.6;
}

.product-field--num {
    flex: 1;
}

.product-field--sm {
    flex: 0.85;
}

.product-field--sm .input-group-text {
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
}

.product-field--btn {
    flex: 0 0 auto;
    padding-bottom: 0;
}

.product-field--btn .btn {
    white-space: nowrap;
    width: auto;
    margin-top: 0;
}

.product-inline-row .form-label {
    font-size: 0.65rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-inline-row .form-control {
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
}

@media (max-width: 1100px) {
    .product-inline-row {
        flex-wrap: wrap;
    }
    .product-field--barcode {
        flex: 1 1 30%;
    }
    .product-field--name {
        flex: 1 1 50%;
    }
    .product-field--unit {
        flex: 1 1 15%;
    }
    .product-field--num {
        flex: 1 1 30%;
    }
    .product-field--sm {
        flex: 1 1 22%;
    }
    .product-field--btn {
        flex: 1 1 100%;
    }
    .product-field--btn .btn {
        width: 100%;
    }
}

/* ===== Form Styling ===== */
.form-label {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-control,
.form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    background-color: #fff;
    color: var(--text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.08);
}

.form-control::placeholder {
    color: #cbd5e1;
}

/* ===== Buttons ===== */
.btn {
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius);
    transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
    letter-spacing: 0.01em;
}

.btn:active {
    transform: scale(0.98);
}

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

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

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

.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Full-width submit inside cards (except inline product row) */
.card-body-custom .btn[type="submit"],
.card-body-custom button.btn {
    width: 100%;
    margin-top: 0.35rem;
}

.product-inline-row .btn[type="submit"],
.product-inline-row button.btn {
    width: auto;
    margin-top: 0;
}

/* ===== Status Messages ===== */
.status-message {
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    margin-top: 0.65rem;
    display: none;
    font-weight: 500;
}

.status-message:not(:empty) {
    display: block;
}

.status-message.status-success {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.status-message.status-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* ===== Table ===== */
.table-items {
    width: 100%;
    font-size: 0.835rem;
    border-collapse: collapse;
}

.table-items thead th {
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 0.6rem 1rem;
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    white-space: nowrap;
}

.table-items tbody td {
    padding: 0.55rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table-items tbody tr:last-child td {
    border-bottom: none;
}

.table-items tbody tr:hover {
    background: #f8fafc;
}

/* Delete button in items table */
.btn-delete-item {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    color: #b00020;
    background: #fff;
    border: 1px solid #b00020;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-delete-item:hover {
    background: #b00020;
    color: #fff;
}

/* PDF download button */
.btn-pdf {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    color: #1565c0;
    background: #fff;
    border: 1px solid #1565c0;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-pdf:hover {
    background: #1565c0;
    color: #fff;
}

/* Reopen button */
.btn-reopen {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    color: #2e7d32;
    background: #fff;
    border: 1px solid #2e7d32;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-reopen:hover {
    background: #2e7d32;
    color: #fff;
}
.btn-reopen:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Archive toolbar */
.archive-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.archive-search {
    flex: 1;
    max-width: 350px;
}
.archive-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

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

.empty-state p {
    margin: 0;
    font-size: 0.85rem;
}

/* ===== Footer ===== */
.footer-app {
    text-align: center;
    padding: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
    letter-spacing: 0.3px;
}

/* ===== Barcode Autocomplete ===== */
.barcode-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 220px;
    overflow-y: auto;
}

.barcode-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.835rem;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.1s;
}

.barcode-item:last-child {
    border-bottom: none;
}

.barcode-item:hover,
.barcode-item.active {
    background: var(--bg);
}

.barcode-code {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.barcode-name {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Invoice Control ===== */
.control-result {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.control-ok {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.control-warn {
    background: #fef2f2;
    border-color: #fecaca;
}

.control-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    flex-shrink: 0;
    line-height: 1;
}

.control-ok .control-icon {
    background: #dcfce7;
    color: #15803d;
    border: 2px solid #86efac;
}

.control-warn .control-icon {
    background: #fee2e2;
    color: #b91c1c;
    border: 2px solid #fca5a5;
}

.control-details {
    flex: 1;
    min-width: 0;
}

.control-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.control-row:last-of-type {
    border-bottom: none;
}

.control-divider {
    margin: 0.4rem 0;
    border: none;
    border-top: 2px solid var(--border);
}

.control-row--highlight {
    background: rgba(0, 0, 0, 0.03);
    margin: 0 -0.5rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
}

.control-row--total {
    background: var(--primary);
    color: #fff;
    margin: 0 -0.5rem;
    padding: 0.45rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    border-bottom: none;
}

.control-row--total strong {
    font-size: 1rem;
}

.control-row--diff {
    margin: 0.25rem -0.5rem 0;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    border-bottom: none;
}

.control-warn .control-row--diff {
    background: #fee2e2;
}

.control-ok .control-row--diff {
    background: #dcfce7;
}

.control-warn .control-row--diff strong {
    color: #b91c1c;
    font-size: 0.95rem;
}

.control-ok .control-row--diff strong {
    color: #15803d;
    font-size: 0.95rem;
}

.control-msg {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    font-weight: 600;
}

.control-warn .control-msg {
    color: #b91c1c;
}

.control-ok .control-msg {
    color: #15803d;
}
