/* ============================================
   PWA ALBARANES - ESTILOS
   Tema: Industrial oscuro con acentos azules
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-primary: #0a0f1c;
    --bg-secondary: #111827;
    --bg-card: #1a2236;
    --bg-input: #0d1424;
    --border: #2a3550;
    --border-focus: #3b82f6;
    --text-primary: #e8ecf4;
    --text-secondary: #8896b0;
    --text-muted: #5a6a84;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.15);
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   LOGIN
   ============================================ */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(16, 185, 129, 0.05) 0%, transparent 40%),
        var(--bg-primary);
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: var(--shadow);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 16px;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

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

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    transition: var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238896b0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #fff;
    padding: 14px;
    font-size: 15px;
    border-radius: var(--radius);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-success:hover {
    background: #059669;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

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

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

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

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

/* ============================================
   APP LAYOUT
   ============================================ */
#app-view {
    display: none;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    overflow: hidden;
}

#app-view.active {
    display: flex;
}

/* HEADER */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 56px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-db-name {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-right select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 28px 6px 10px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%238896b0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* TABS */
.tab-bar {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}

.tab-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* CONTENT AREA */
.content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.tab-panel {
    display: none;
    padding: 16px;
    padding-bottom: 80px;
}

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

/* ============================================
   NUEVO ALBARÁN
   ============================================ */
.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.albaran-form .form-group {
    margin-bottom: 14px;
}

.albaran-form .form-group select,
.albaran-form .form-group input {
    font-size: 14px;
    padding: 11px 12px;
}

.linea-producto {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    position: relative;
}

.linea-producto .linea-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.linea-producto .linea-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 2px 8px;
    border-radius: 4px;
}

.linea-producto .btn-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: var(--transition);
}

.linea-producto .btn-remove:hover {
    color: var(--danger);
}

.linea-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.linea-grid .row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.linea-grid label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.linea-grid input,
.linea-grid select {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.linea-grid input:focus,
.linea-grid select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.linea-grid input[type="number"] {
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
}

.btn-add-line {
    width: 100%;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 16px;
}

.btn-add-line:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 16px;
}

.form-actions .btn {
    padding: 14px;
}

/* ============================================
   LISTA ALBARANES
   ============================================ */
.filtros-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.filtros-bar input,
.filtros-bar select {
    flex: 1;
    min-width: 120px;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.albaran-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.albaran-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow);
}

.albaran-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.albaran-card-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
}

.albaran-card-total {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 700;
    color: var(--success);
}

.albaran-card-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.albaran-card-client {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 60%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.albaran-card-date {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

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

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

/* ============================================
   MODAL DETALLE ALBARÁN
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(4px);
}

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

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    background: var(--bg-card);
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
    padding: 24px 16px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 20px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(42, 53, 80, 0.5);
    font-size: 14px;
}

.detail-row .label {
    color: var(--text-secondary);
}

.detail-row .value {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.detail-lineas {
    margin-top: 16px;
}

.detail-linea {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(42, 53, 80, 0.5);
    font-size: 13px;
    align-items: center;
}

.detail-linea .desc {
    color: var(--text-primary);
}

.detail-linea .qty,
.detail-linea .price,
.detail-linea .imp {
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
    font-size: 12px;
}

.detail-linea .imp {
    font-weight: 700;
    color: var(--success);
}

.detail-totales {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 2px solid var(--border);
}

.detail-totales .detail-row .value {
    font-size: 15px;
}

.detail-totales .total-final .value {
    color: var(--success);
    font-size: 18px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions .btn {
    flex: 1;
    padding: 14px;
}

/* ============================================
   FIRMA DE ENTREGA
   ============================================ */
.firma-canvas-wrap {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 10px;
    touch-action: none;
}

#firma-canvas {
    display: block;
    width: 100%;
    height: 220px;
    border-radius: var(--radius-sm);
    cursor: crosshair;
}

.firma-thumb {
    max-width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

/* ============================================
   VISTA PREVIA DEL TICKET
   ============================================ */
.ticket-preview {
    background: #ffffff;
    color: #111827;
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-top: 10px;
    max-width: 340px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.ticket-preview pre {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}

/* ============================================
   TOAST / NOTIFICACIONES
   ============================================ */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    left: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s;
    pointer-events: auto;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.warning {
    border-left: 3px solid var(--warning);
}

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

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================
   LOADING / SPINNER
   ============================================ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 600px) {
    .tab-panel {
        max-width: 560px;
        margin: 0 auto;
    }
    .modal-content {
        border-radius: 16px;
        margin-bottom: 20px;
    }
    .modal-overlay {
        align-items: center;
    }
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
