/* Heaven Flow — Mobile-first */

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

:root {
    --bg:         #0f172a;
    --bg-card:    #1e293b;
    --bg-input:   #0f172a;
    --border:     #334155;
    --text:       #f1f5f9;
    --text-muted: #94a3b8;
    --primary:    #6366f1;
    --primary-h:  #4f46e5;
    --danger:     #ef4444;
    --success:    #22c55e;
    --warning:    #f59e0b;
    --radius:     10px;
    --radius-sm:  6px;
}

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Layout ── */

.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-logo {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary);
    letter-spacing: -.01em;
    flex-shrink: 0;
}

.topbar-nav {
    display: flex;
    gap: .25rem;
    flex: 1;
    overflow-x: auto;
}

.nav-link {
    padding: .35rem .65rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: .875rem;
    white-space: nowrap;
}
.nav-link:hover, .nav-link.active {
    background: rgba(99,102,241,.15);
    color: var(--primary);
    text-decoration: none;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-shrink: 0;
}

.user-name { color: var(--text-muted); font-size: .8rem; }
.logout-link { font-size: .8rem; color: var(--text-muted); }
.logout-link:hover { color: var(--danger); }

.main-content {
    flex: 1;
    padding: 1.25rem 1rem;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

/* ── Auth ── */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 380px;
}

.auth-logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.25rem;
}

.auth-title {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
}

.auth-form { display: flex; flex-direction: column; gap: .85rem; }

.auth-footer {
    margin-top: 1.25rem;
    font-size: .875rem;
    color: var(--text-muted);
    text-align: center;
}

/* ── Fields ── */

.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .8rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: .6rem .75rem;
    font-size: .95rem;
    width: 100%;
    outline: none;
    transition: border-color .15s;
}

input:focus, select:focus {
    border-color: var(--primary);
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .6rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-full { width: 100%; }

.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); border-color: var(--primary-h); text-decoration: none; }

.btn-danger   { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.1); }

.btn-ghost    { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.05); color: var(--text); }

.btn-pack     { background: var(--warning); color: #0f172a; border-color: var(--warning); font-size: 1.05rem; padding: .85rem; }
.btn-pack:hover:not(:disabled)    { background: #d97706; }

.btn-transit  { background: #3b82f6; color: #fff; border-color: #3b82f6; font-size: 1.05rem; padding: .85rem; }
.btn-transit:hover:not(:disabled) { background: #2563eb; }

.btn-deliver  { background: var(--success); color: #fff; border-color: var(--success); font-size: 1.05rem; padding: .85rem; }
.btn-deliver:hover:not(:disabled) { background: #16a34a; }

.btn-sm { padding: .35rem .65rem; font-size: .8rem; }

/* ── Alerts ── */

.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    margin-bottom: .5rem;
}
.alert-error   { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); color: #86efac; }

/* ── Badges ── */

.badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-green { background: rgba(34,197,94,.15); color: #86efac; }
.badge-gray  { background: rgba(148,163,184,.15); color: #94a3b8; }
.badge-blue  { background: rgba(99,102,241,.15); color: #a5b4fc; }
.badge-red   { background: rgba(239,68,68,.15); color: #fca5a5; }

/* ── Cards ── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ── Page header ── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-header h2 { font-size: 1.2rem; }

/* ── Form grid ── */

.form-grid { display: flex; flex-direction: column; gap: .85rem; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ── Connections list ── */

.connections-list { display: flex; flex-direction: column; gap: .65rem; }

.connection-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.connection-card.inactive { opacity: .55; }

.connection-info { flex: 1; min-width: 0; }
.connection-name { display: block; font-weight: 600; }
.connection-url  { font-size: .8rem; color: var(--text-muted); }

.connection-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
}

/* ── Dashboard ── */

.welcome {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.select-connection {
    margin-bottom: 1.5rem;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .85rem;
}

.action-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    text-decoration: none;
    color: var(--text);
}

.action-card:hover {
    border-color: var(--primary);
    background: rgba(99,102,241,.08);
    text-decoration: none;
    color: var(--text);
}

.action-scan { grid-column: 1 / -1; }

.action-icon { font-size: 2rem; }
.action-label { font-size: .9rem; font-weight: 500; }

/* ── Scanner ── */

.scanner-connection-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}

.scanner-connection-bar label { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }
.scanner-connection-bar select { flex: 1; }

.scanner-screen { display: none; }
.scanner-screen.active { display: block; }

#qr-reader {
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    margin-bottom: .75rem;
}

/* Ajuste del widget html5-qrcode */
#qr-reader video { border-radius: var(--radius); }
#qr-reader img   { display: none; }

.scanner-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: .875rem;
    margin-bottom: .75rem;
}

.order-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    margin-bottom: 1rem;
}

.order-loading { color: var(--text-muted); text-align: center; padding: 1.5rem 0; }

.order-meta { margin-bottom: .75rem; }
.order-id     { font-size: 1.2rem; font-weight: 700; }
.order-client { color: var(--text-muted); font-size: .9rem; }
.order-envio  { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

.order-items {
    list-style: none;
    border-top: 1px solid var(--border);
    padding-top: .6rem;
    margin-top: .6rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .875rem;
    color: var(--text-muted);
}

.order-tracking {
    margin-top: .6rem;
    font-size: .85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: .6rem;
}

.confirm-actions {
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.result-box {
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    margin-bottom: 1rem;
}

.result-ok    { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); }
.result-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); }

.result-icon    { font-size: 3rem; margin-bottom: .75rem; }
.result-message { font-size: 1rem; }

/* ── History ── */

.filter-form select { max-width: 220px; }

.log-table-wrap { overflow-x: auto; }

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

.log-table th {
    text-align: left;
    padding: .5rem .75rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.log-table td {
    padding: .65rem .75rem;
    border-bottom: 1px solid rgba(51,65,85,.5);
    vertical-align: middle;
}

.log-date { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }

.pagination {
    display: flex;
    gap: .4rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.page-link {
    padding: .4rem .7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .875rem;
}
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
}

/* ── Utilities ── */

.mt { margin-top: .75rem; }

/* ── Desktop ── */

@media (min-width: 600px) {
    .main-content { padding: 1.75rem 1.5rem; }
    .action-grid  { grid-template-columns: repeat(3, 1fr); }
    .action-scan  { grid-column: auto; }
    .auth-body    { padding: 2rem; }
}
