/* =============================================
   Encomendas - 4MAX Control
   Estilo baseado nas telas do aplicativo
   ============================================= */

:root {
    --green: #0D9F6E;
    --green-light: #DEF7EC;
    --green-dark: #046C4E;
    --orange: #E67E22;
    --orange-light: #FFF4E6;
    --blue: #3B82F6;
    --blue-light: #EBF5FF;
    --red: #E53E3E;
    --red-light: #FFF5F5;
    --yellow: #F6C343;
    --yellow-light: #FFFBEA;

    --bg: #F0F2F5;
    --bg-card: #FFFFFF;
    --bg-section: #F8F9FA;
    --text: #1A1D21;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --font: 'Plus Jakarta Sans', -apple-system, sans-serif;
    --header-h: 56px;
}

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

html, body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ===== HEADER ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 100;
    gap: 8px;
}

.header-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    transition: background 0.2s;
}

.header-btn:active { background: var(--bg); }

.header-title {
    flex: 1;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* ===== SIDEBAR ===== */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--bg-card);
    z-index: 201;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.sidebar.open { left: 0; }

.sidebar-header {
    padding: 32px 20px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    width: 48px;
    height: 48px;
    background: var(--green);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFF;
    margin-bottom: 12px;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 800;
}

.sidebar-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-menu {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
}

.sidebar-menu li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 15px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.sidebar-menu li:active { background: var(--bg); }
.sidebar-menu li.active {
    background: var(--green-light);
    color: var(--green-dark);
    font-weight: 600;
}

.sidebar-menu li .material-icons-round { font-size: 22px; }

/* ===== MAIN ===== */
.app-main {
    margin-top: var(--header-h);
    padding: 16px;
    padding-bottom: 40px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* ===== PAGES ===== */
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
}

.page-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 2px;
}

.back-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    flex-shrink: 0;
    margin-top: 2px;
}

/* ===== ACTION CARDS ===== */
.action-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.action-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.action-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-lg);
}

.action-card__icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 32px;
    font-weight: 800;
    color: #FFF;
}

.action-card__icon--green { background: var(--green); }
.action-card__icon--orange { background: var(--orange); }

.action-card h3 {
    font-size: 20px;
    font-weight: 700;
}

/* ===== STAT CARDS ===== */
.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.stat-card__content { flex: 1; }

.stat-card__label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-card__number {
    display: block;
    font-size: 36px;
    font-weight: 800;
    line-height: 1.1;
    margin: 4px 0;
}

.stat-card__sub {
    font-size: 13px;
    color: var(--green);
    font-weight: 500;
}

.stat-trend { font-size: 12px; }

.stat-card__icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFF;
    flex-shrink: 0;
}

.stat-card__icon--orange { background: var(--orange); }
.stat-card__icon--blue { background: var(--blue); }
.stat-card__icon--green { background: var(--green); }

/* ===== SECTION BLOCK ===== */
.section-block {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.section-header h3 {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.section-icon { font-size: 24px; color: var(--green); }

.refresh-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: none;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
}

/* ===== CARD LIST ===== */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.list-card {
    border: 2px solid var(--yellow);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--yellow-light);
    cursor: pointer;
    transition: transform 0.1s;
}

.list-card:active { transform: scale(0.99); }

.list-card--done {
    border-color: var(--green);
    background: var(--green-light);
}

.list-card__name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
}

.list-card__phone {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.list-card__phone .material-icons-round { font-size: 16px; }

.list-card__code {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.list-card__date {
    display: inline-block;
    margin-top: 6px;
    padding: 3px 10px;
    background: var(--bg-card);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.list-card__status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.list-card__status--pendente {
    background: var(--orange-light);
    color: var(--orange);
    border: 1px solid #FBBF24;
}

.list-card__status--retirada {
    background: var(--green-light);
    color: var(--green);
    border: 1px solid #6EE7B7;
}

.list-card__desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.list-card__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

/* ===== FORM CARDS ===== */
.form-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.form-card__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.form-card__header .material-icons-round {
    font-size: 24px;
    color: var(--text-secondary);
}

.form-card__header h3 {
    font-size: 18px;
    font-weight: 700;
}

.form-group {
    margin-bottom: 16px;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: var(--bg-card);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(13,159,110,0.1);
}

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

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

.input-with-action {
    display: flex;
    gap: 8px;
}

.input-with-action input { flex: 1; }

.input-action-btn {
    width: 48px;
    height: 48px;
    border: 1.5px solid var(--border);
    background: var(--bg-section);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* ===== SEARCH SELECT ===== */
.search-select { position: relative; }

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 0 14px;
    background: var(--bg-card);
    transition: border-color 0.2s;
}

.search-input-wrap:focus-within {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(13,159,110,0.1);
}

.search-input-wrap .material-icons-round {
    color: var(--text-muted);
    font-size: 20px;
}

.search-input-wrap input {
    flex: 1;
    border: none;
    padding: 12px 0;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    outline: none;
    background: transparent;
}

.search-results {
    position: absolute;
    top: calc(100%);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-xs) var(--radius-xs);
    max-height: 250px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: var(--shadow-lg);
}

.search-results .result-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--bg);
    transition: background 0.15s;
}

.search-results .result-item:active { background: var(--bg); }

.result-item__name {
    font-size: 14px;
    font-weight: 700;
}

.result-item__info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.selected-info {
    margin-top: 12px;
    padding: 14px;
    background: var(--green-light);
    border: 1.5px solid #6EE7B7;
    border-radius: var(--radius-xs);
}

.selected-info h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--green-dark);
    margin-bottom: 8px;
}

.selected-info p {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 4px;
}

/* ===== FOTO PREVIEW ===== */
.foto-preview {
    margin-bottom: 12px;
}

.foto-preview img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius-xs);
    border: 2px solid var(--green-light);
}

.foto-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0;
    font-size: 14px;
    font-weight: 500;
}

.foto-status.success { color: var(--green); }
.foto-status.error { color: var(--red); }
.foto-status .material-icons-round { font-size: 20px; }

/* ===== SIGNATURE PAD ===== */
.signature-pad-wrap {
    border: 2px dashed var(--border);
    border-radius: var(--radius-xs);
    padding: 8px;
    margin-bottom: 8px;
    background: #FAFAFA;
    touch-action: none;
}

.signature-pad-wrap canvas {
    width: 100%;
    height: 200px;
    display: block;
    cursor: crosshair;
}

.signature-hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.signature-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.signature-actions .btn { flex: 1; }

/* ===== INFO GRID ===== */
.info-grid { display: flex; flex-direction: column; gap: 12px; }

.info-item {}
.info-label { display: block; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.info-value { display: block; font-size: 15px; font-weight: 600; margin-top: 2px; }
.info-code {
    display: inline-block;
    background: var(--bg);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.info-item-row { display: flex; gap: 16px; }
.info-item-row .info-item { flex: 1; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-xs);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn .material-icons-round { font-size: 20px; }

.btn--primary { background: var(--blue); color: #FFF; }
.btn--primary:active { background: #2563EB; }

.btn--success { background: var(--green); color: #FFF; }
.btn--success:active { background: var(--green-dark); }

.btn--outline {
    background: var(--bg-card);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn--outline:active { background: var(--bg); }

.btn--full { width: 100%; }
.btn--lg { padding: 16px 24px; font-size: 16px; border-radius: var(--radius-sm); }

.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ===== SUCCESS OVERLAY ===== */
.success-overlay {
    position: fixed;
    inset: 0;
    background: var(--green-light);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.success-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    width: 90%;
}

.success-icon {
    width: 72px;
    height: 72px;
    background: var(--green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: #FFF;
}

.success-icon .material-icons-round { font-size: 36px; }
.success-card h2 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.success-card p { font-size: 14px; color: var(--green); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 420px;
    width: 100%;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.scanner-area {
    position: relative;
    width: 100%;
    height: 260px;
    background: #000;
    border-radius: var(--radius-xs);
    overflow: hidden;
    margin-bottom: 16px;
}

.scanner-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-line {
    position: absolute;
    left: 10%;
    right: 10%;
    height: 2px;
    background: var(--red);
    top: 50%;
    animation: scanMove 2s ease-in-out infinite;
    box-shadow: 0 0 8px var(--red);
}

@keyframes scanMove {
    0%, 100% { top: 30%; }
    50% { top: 70%; }
}

/* ===== LOADING ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 16px;
    right: 16px;
    z-index: 600;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 400px;
    margin: 0 auto;
}

.toast {
    padding: 14px 18px;
    border-radius: var(--radius-xs);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast--success { background: var(--green); color: #FFF; }
.toast--error { background: var(--red); color: #FFF; }
.toast--info { background: var(--blue); color: #FFF; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.empty-state .material-icons-round {
    font-size: 48px;
    margin-bottom: 8px;
    opacity: 0.4;
}

.empty-state p { font-size: 14px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
    .action-cards { flex-direction: row; }
    .action-card { flex: 1; }
}

@media (min-width: 768px) {
    .app-main { padding: 24px; }
    .stats-grid { flex-direction: row; }
    .stat-card { flex: 1; }
}

/* ===== VALIDATION ERROR STATE ===== */
.form-group.has-error input,
.form-group.has-error textarea {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(229,62,62,0.1);
}

.validation-error {
    color: var(--red);
    font-size: 13px;
    font-weight: 500;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.validation-error .material-icons-round { font-size: 16px; }
