/* ============================================================
   ALPHA POSITIONING SYSTEMS - ESTILOS GLOBAIS
   Paleta: Azul #1F3A70 | Verde #7FBF3F | Branco #FFFFFF
   ============================================================ */

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

:root {
    --blue: #1F3A70;
    --blue-dark: #162d58;
    --blue-light: #2a4d94;
    --green: #7FBF3F;
    --green-dark: #6BA830;
    --green-light: #93d44e;
    --white: #ffffff;
    --gray-50: #f8f9fa;
    --gray-100: #f0f2f5;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --red: #dc2626;
    --red-light: #fef2f2;
    --orange: #f59e0b;
    --orange-light: #fffbeb;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--gray-50);
    min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--green); }

/* --- Header --- */
.app-header {
    background: var(--white);
    border-bottom: 3px solid var(--green);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 68px;
    gap: 16px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.header-logo img {
    height: 44px;
    width: auto;
}

.header-logo-text {
    font-size: 13px;
    color: var(--gray-500);
    line-height: 1.3;
}

.header-logo-text strong {
    display: block;
    font-size: 15px;
    color: var(--blue);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: var(--gray-100);
    border-radius: 24px;
    font-size: 13px;
    color: var(--gray-600);
}

.header-user .user-name {
    font-weight: 600;
    color: var(--blue);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

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

.btn-primary {
    background: var(--green);
    color: var(--white);
}
.btn-primary:hover:not(:disabled) {
    background: var(--green-dark);
    color: var(--white);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(127,191,63,0.35);
}

.btn-blue {
    background: var(--blue);
    color: var(--white);
}
.btn-blue:hover:not(:disabled) {
    background: var(--blue-dark);
    color: var(--white);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31,58,112,0.35);
}

.btn-outline {
    background: transparent;
    color: var(--blue);
    border: 2px solid var(--blue);
}
.btn-outline:hover:not(:disabled) {
    background: var(--blue);
    color: var(--white);
}

.btn-outline-green {
    background: transparent;
    color: var(--green-dark);
    border: 2px solid var(--green);
}
.btn-outline-green:hover:not(:disabled) {
    background: var(--green);
    color: var(--white);
}

.btn-danger {
    background: var(--red);
    color: var(--white);
}
.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
    color: var(--white);
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-800);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-lg {
    padding: 13px 28px;
    font-size: 16px;
}

.btn-full { width: 100%; }

.btn-icon {
    padding: 8px;
    border-radius: 6px;
}

/* --- Cards --- */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--blue);
    display: flex;
    align-items: center;
    gap: 9px;
}

.card-body {
    padding: 24px;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-label .required {
    color: var(--red);
    margin-left: 3px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--gray-800);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(127,191,63,0.15);
}

.form-control::placeholder { color: var(--gray-400); }

.form-control.error {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(220,38,38,0.10);
}

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

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.form-hint {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 4px;
}

.form-error {
    font-size: 12px;
    color: var(--red);
    margin-top: 4px;
}

/* --- Alerts --- */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--red-light);
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-success {
    background: var(--success-light);
    color: #15803d;
    border: 1px solid #86efac;
}

.alert-warning {
    background: var(--orange-light);
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert-info {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
}

/* --- Badges / Status --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-approved { background: var(--success-light); color: #15803d; }
.badge-denied { background: var(--red-light); color: #991b1b; }
.badge-partial { background: #fff7ed; color: #9a3412; }
.badge-received { background: var(--success-light); color: #15803d; }
.badge-shipped { background: #eff6ff; color: #1d4ed8; }

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    background: var(--blue);
    color: var(--white);
    padding: 12px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.data-table thead th:first-child { border-radius: 0; }

.data-table tbody tr {
    border-bottom: 1px solid var(--gray-200);
    transition: background var(--transition);
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--gray-50); }

.data-table tbody td {
    padding: 12px 14px;
    color: var(--gray-700);
    vertical-align: middle;
}

.data-table tfoot td {
    padding: 12px 14px;
    font-weight: 700;
    background: var(--gray-100);
    border-top: 2px solid var(--gray-300);
}

/* --- Order Items Table (inline editing) --- */
.order-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.order-table th {
    background: var(--blue);
    color: var(--white);
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.order-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

.order-table tr:hover td { background: var(--gray-50); }

.order-table .col-pn { width: 160px; }
.order-table .col-desc { min-width: 220px; }
.order-table .col-qty { width: 90px; }
.order-table .col-price { width: 120px; }
.order-table .col-total { width: 130px; }
.order-table .col-action { width: 50px; text-align: center; }

.order-table input.pn-input,
.order-table input.qty-input {
    width: 100%;
    padding: 7px 10px;
    border: 1.5px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    transition: border-color var(--transition);
}

.order-table input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(127,191,63,0.15);
}

.order-table .desc-cell {
    font-size: 13px;
    color: var(--gray-600);
    min-height: 32px;
    padding: 7px 10px;
}

.order-table .desc-cell.found { color: var(--gray-800); }
.order-table .desc-cell.not-found { color: var(--red); font-style: italic; }
.order-table .desc-cell.loading { color: var(--gray-400); font-style: italic; }

.order-table .price-cell,
.order-table .total-cell {
    font-size: 13px;
    color: var(--gray-700);
    text-align: right;
    padding-right: 12px;
    font-variant-numeric: tabular-nums;
}

.order-table .total-cell { font-weight: 600; color: var(--blue); }

.order-table tfoot td {
    padding: 10px 12px;
    background: var(--gray-100);
    border-top: 2px solid var(--gray-300);
    font-weight: 700;
}

.order-table .grand-total {
    font-size: 16px;
    color: var(--blue);
    text-align: right;
    padding-right: 12px;
}

.btn-remove-row {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    transition: color var(--transition), background var(--transition);
}

.btn-remove-row:hover {
    color: var(--red);
    background: var(--red-light);
}

/* --- Autocomplete dropdown --- */
.pn-wrapper {
    position: relative;
}

.pn-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1.5px solid var(--green);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    max-height: 220px;
    overflow-y: auto;
    display: none;
}

.pn-dropdown.open { display: block; }

.pn-option {
    padding: 9px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
    transition: background var(--transition);
}

.pn-option:last-child { border-bottom: none; }
.pn-option:hover, .pn-option.active { background: var(--gray-100); }

.pn-option .pn-code {
    font-weight: 700;
    color: var(--blue);
    font-size: 12px;
    margin-right: 8px;
}

.pn-option .pn-desc {
    color: var(--gray-600);
}

.pn-option .pn-price {
    float: right;
    font-weight: 600;
    color: var(--green-dark);
    font-size: 12px;
}

/* --- Sections / Layout --- */
.page-hero {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-light) 100%);
    color: var(--white);
    padding: 40px 24px;
    text-align: center;
}

.page-hero h1 {
    font-size: 2em;
    margin-bottom: 8px;
}

.page-hero p {
    font-size: 1em;
    opacity: 0.85;
    max-width: 600px;
    margin: 0 auto;
}

.page-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--blue);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--green);
    display: flex;
    align-items: center;
    gap: 9px;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 24px;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 7px;
}

.tab-btn:hover { color: var(--blue); }

.tab-btn.active {
    color: var(--blue);
    border-bottom-color: var(--green);
}

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

/* --- Status Steps (rastreamento) --- */
.status-track {
    display: flex;
    gap: 0;
    margin: 20px 0;
}

.status-step {
    flex: 1;
    text-align: center;
    position: relative;
}

.status-step::before {
    content: '';
    position: absolute;
    top: 18px;
    left: 50%;
    right: -50%;
    height: 3px;
    background: var(--gray-200);
    z-index: 0;
}

.status-step:last-child::before { display: none; }

.step-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-400);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin: 0 auto 8px;
    position: relative;
    z-index: 1;
    transition: all var(--transition);
}

.status-step.done .step-icon {
    background: var(--green);
    color: var(--white);
}

.status-step.active .step-icon {
    background: var(--blue);
    color: var(--white);
    box-shadow: 0 0 0 4px rgba(31,58,112,0.15);
}

.status-step.denied .step-icon {
    background: var(--red);
    color: var(--white);
}

.step-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.step-value {
    font-size: 11px;
    color: var(--gray-400);
    margin-top: 2px;
}

.status-step.done .step-label,
.status-step.active .step-label { color: var(--blue); }

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95) translateY(20px);
    transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1) translateY(0); }

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

.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--blue);
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
    transition: color var(--transition);
}

.modal-close:hover { color: var(--gray-700); }

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* --- Terms box --- */
.terms-box {
    background: var(--gray-50);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--gray-600);
    max-height: 160px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.terms-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
}

.terms-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--green);
    cursor: pointer;
    flex-shrink: 0;
}

/* --- Loading spinner --- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-size: 15px;
    color: var(--blue);
    font-weight: 600;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 20px;
}

/* --- Footer --- */
.app-footer {
    background: var(--blue);
    color: rgba(255,255,255,0.75);
    text-align: center;
    padding: 24px 20px;
    font-size: 13px;
    margin-top: 60px;
}

.app-footer a { color: var(--green-light); }

/* --- Utility --- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-blue { color: var(--blue); }
.text-green { color: var(--green-dark); }
.text-red { color: var(--red); }
.text-muted { color: var(--gray-400); }
.font-bold { font-weight: 700; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 0;
        gap: 10px;
    }

    .header-logo-text { display: none; }

    .form-row, .form-row-3 {
        grid-template-columns: 1fr;
    }

    .page-hero h1 { font-size: 1.5em; }

    .page-content { padding: 20px 16px; }

    .card-body { padding: 16px; }

    .tabs { overflow-x: auto; }

    .status-track { flex-direction: column; gap: 12px; }
    .status-step::before { display: none; }

    .modal { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; }
    .modal-overlay { align-items: flex-end; padding: 0; }

    .order-table .col-desc { min-width: 140px; }
    .order-table .col-price { width: 90px; }
    .order-table .col-total { width: 90px; }

    .btn-lg { padding: 11px 20px; font-size: 15px; }

    .data-table { font-size: 13px; }
    .data-table thead th, .data-table tbody td { padding: 9px 10px; }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    .header-nav .btn span { display: none; }
    .header-user .user-name { max-width: 120px; }
}
