/* ==============================================================================
   BELICH INVOICE - SYSTEM DESIGN & SIDEBAR LAYOUT STYLES
   Ferretería & Facturación e-CF DGII (República Dominicana)
   ============================================================================== */

:root {
    color-scheme: light;
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    /* Color Palette */
    --brand-dark: #0b132b;        /* Midnight Dark Navy Sidebar */
    --brand-border: #1c2541;      /* Deep Navy Border */
    --brand-accent: #d97706;      /* Amber 600 Hardware Gold */
    --brand-accent-hover: #b45309;/* Amber 700 */
    --brand-green: #059669;       /* Emerald 600 DGII Green */
    --bg-app: #f8fafc;           /* Slate 50 */
    
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --white: #ffffff;
    
    --green: #d97706;
    --mint: #fff5e5;
    --logo-bg: #eeebe4;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background-color: var(--bg-app);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin-top: 0; }

.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }

/* ------------------------------------------------------------------------------
   1. APP LAYOUT & DISTINCT SIDEBAR STRUCTURE
   ------------------------------------------------------------------------------ */

.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 19, 43, 0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--brand-dark);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1000;
    border-right: 1px solid var(--brand-border);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--brand-border);
    background: #080d1e;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #d97706, #b45309);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.35);
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #ffffff;
    text-decoration: none;
}

.sidebar-brand-sub {
    font-size: 0.68rem;
    color: #94a3b8;
    font-weight: 600;
}

.sidebar-menu {
    padding: 16px 10px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-label {
    padding: 10px 10px 4px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #5bc0be;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #8d99ae;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.18s ease;
}

.sidebar-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-link.active {
    color: #ffffff;
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.25), rgba(217, 119, 6, 0.08));
    border-left: 4px solid var(--brand-accent);
    padding-left: 8px;
    font-weight: 750;
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar-link.active .sidebar-icon {
    opacity: 1;
    color: #f59e0b;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--brand-border);
    background: #080d1e;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.sidebar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #1c2541;
    color: #f8fafc;
    font-weight: 800;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid #3a506b;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.68rem;
    color: #f59e0b;
    font-weight: 600;
}

/* ------------------------------------------------------------------------------
   2. TOPBAR HEADER & PROFESSIONAL BUTTONS
   ------------------------------------------------------------------------------ */

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: var(--bg-app);
}

.app-topbar {
    height: 64px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    gap: 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-with-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.topbar-brand-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-brand-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ink);
}

.topbar-badge {
    font-size: 0.68rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 20px;
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

/* NAVIGATION PILL BUTTONS IN HEADER CENTER */
.topbar-nav-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.nav-pill {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
    text-decoration: none;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.nav-pill:hover {
    color: var(--ink);
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.nav-pill.active {
    color: #ffffff;
    background: var(--brand-accent);
    box-shadow: 0 2px 6px rgba(217, 119, 6, 0.3);
}

/* TOPBAR RIGHT SECTION & USER BADGE */
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 6px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 30px;
}

.user-badge-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand-accent);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-badge-details {
    display: flex;
    flex-direction: column;
}

.user-badge-name {
    font-size: 0.78rem;
    font-weight: 750;
    color: var(--ink);
    line-height: 1.2;
}

.user-badge-role {
    font-size: 0.65rem;
    color: var(--muted);
    font-weight: 600;
}

/* DISCREET SIDE-BY-SIDE BUTTONS (SIDEBAR TOGGLE & LOGOUT) */
.discreet-buttons-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

button.btn-discreet {
    width: 36px !important;
    height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    border: 1px solid var(--line) !important;
    border-radius: 9px !important;
    color: #475569 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

button.btn-discreet:hover {
    background: #f1f5f9 !important;
    color: var(--ink) !important;
    border-color: #cbd5e1 !important;
}

button.btn-discreet-danger:hover {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border-color: #fecaca !important;
}

.app-body {
    flex: 1;
    padding: 24px;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.container {
    width: 100%;
    margin: 0;
}

/* ------------------------------------------------------------------------------
   3. DASHBOARD PAGE & 2-COLUMN GRID LAYOUT
   ------------------------------------------------------------------------------ */

.dashboard-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 24px;
    align-items: start;
}

.dashboard-left-col {
    display: flex;
    flex-direction: column;
}

.dashboard-right-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dashboard-header-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    padding: 22px 24px;
    border-radius: 14px;
    border: 1px solid var(--line);
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.dashboard-header-banner h1 {
    font-size: 1.4rem;
    font-weight: 800;
    margin: 4px 0;
    color: var(--ink);
}

.dgii-status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 30px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    padding: 16px 18px;
    border-radius: 12px;
    border: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
}

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

.stat-card-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
}

.stat-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.icon-amber { background: #fffbebf5; border: 1px solid #fef3c7; }
.icon-blue { background: #eff6ff; border: 1px solid #dbeafe; }
.icon-green { background: #f0fdf4; border: 1px solid #dcfce7; }
.icon-red { background: #fef2f2; border: 1px solid #fee2e2; }
.icon-purple { background: #faf5ff; border: 1px solid #f3e8ff; }

.stat-card-value {
    font-size: 1.35rem;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--ink);
    margin-bottom: 2px;
}

.stat-card-value small {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    font-family: var(--font-sans);
}

.stat-card-sub {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.text-danger { color: #dc2626 !important; font-weight: 700; }
.text-warning { color: #d97706 !important; font-weight: 700; }

/* ------------------------------------------------------------------------------
   4. QUICK ACTIONS
   ------------------------------------------------------------------------------ */

.quick-actions-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 12px;
    color: var(--ink);
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.action-card {
    background: white;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    text-decoration: none;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.18s ease;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
    border-color: var(--brand-accent);
}

.action-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
    flex-shrink: 0;
}

.action-icon-amber { background: #fff7ed; color: #ea580c; border: 1px solid #ffedd5; }
.action-icon-blue { background: #eff6ff; color: #2563eb; border: 1px solid #dbeafe; }
.action-icon-green { background: #f0fdf4; color: #16a34a; border: 1px solid #dcfce7; }
.action-icon-red { background: #fef2f2; color: #dc2626; border: 1px solid #fee2e2; }
.action-icon-purple { background: #faf5ff; color: #9333ea; border: 1px solid #f3e8ff; }

.action-details h3 {
    margin: 0 0 2px;
    font-size: 0.88rem;
    font-weight: 750;
    color: var(--ink);
}

.action-details p {
    margin: 0;
    font-size: 0.72rem;
    color: var(--muted);
}

/* ------------------------------------------------------------------------------
   5. PANELS & TABLES STYLING
   ------------------------------------------------------------------------------ */

.panel {
    background: white;
    padding: 20px;
    border-radius: 14px;
    border: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    margin-bottom: 20px;
    overflow: auto;
}

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

.panel h2 {
    font-size: 0.98rem;
    font-weight: 800;
    margin: 0;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.page-head h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0;
}

.eyebrow {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--brand-accent);
    margin-bottom: 4px;
}

.muted { color: var(--muted); }

/* Form Controls */
label {
    display: block;
    margin: 12px 0 5px;
    font-weight: 650;
    font-size: 0.85rem;
    color: #334155;
}

input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: white;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

button {
    width: 100%;
    margin-top: 18px;
    padding: 10px 16px;
    border: 0;
    border-radius: 8px;
    color: white;
    background: var(--brand-accent);
    font-family: inherit;
    font-weight: 750;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

button:hover {
    background: var(--brand-accent-hover);
}

button:active {
    transform: scale(0.99);
}

.button-secondary {
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: white;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.85rem;
}

.primary-link {
    display: inline-block;
    padding: 9px 15px;
    border-radius: 8px;
    color: white;
    background: var(--brand-accent);
    text-decoration: none;
    font-weight: 800;
    font-size: 0.85rem;
}

.primary-link:hover {
    background: var(--brand-accent-hover);
}

/* Nav Tabs */
.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0 22px;
}

.nav-tabs a {
    padding: 7px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: white;
    text-decoration: none;
    font-weight: 650;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.nav-tabs a.active {
    color: white;
    border-color: var(--brand-accent);
    background: var(--brand-accent);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
    font-size: 0.85rem;
}

th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

tbody tr:hover {
    background-color: #f8fafc;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    background: #ecfdf5;
    color: #047857;
    font-size: 0.72rem;
    font-weight: 800;
}

.badge.danger { color: #b91c1c; background: #fef2f2; }
.badge.warning { color: #b45309; background: #fffbe6; }

.status-pagada { color: #047857; background: #ecfdf5; }
.status-emitida, .status-parcial { color: #b45309; background: #fffbe6; }
.status-anulada { color: #b91c1c; background: #fef2f2; }

.sku-tag {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 2px 5px;
    background: #f1f5f9;
    border-radius: 4px;
    color: #475569;
}

.text-action {
    color: var(--brand-accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.82rem;
}

.text-action:hover {
    text-decoration: underline;
}

.alert {
    margin: 16px 0;
    padding: 12px 14px;
    border-radius: 8px;
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #fecaca;
    font-weight: 600;
    font-size: 0.88rem;
}

.success {
    margin: 16px 0;
    padding: 12px 14px;
    border-radius: 8px;
    color: #065f46;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    font-weight: 600;
    font-size: 0.88rem;
}

/* Billing & Invoice Layout */
.wide-container { width: 100%; }
.billing-layout { display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: 24px; align-items: start; }
.billing-layout aside { position: sticky; top: 82px; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.search-row button { width: auto; margin: 0; }
.product-results { display: grid; gap: 8px; margin-top: 10px; }
.product-results button { display: flex; align-items: flex-start; flex-direction: column; width: 100%; margin: 0; padding: 12px 14px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 10px; text-align: left; transition: all 0.15s; }
.product-results button:hover { border-color: var(--brand-accent); background: var(--mint); }
.product-results span { color: var(--muted); font-size: .85rem; }
.invoice-table-wrap { overflow: auto; }
#invoice-lines td:first-child { min-width: 230px; }
#invoice-lines td small { display: block; color: var(--muted); }
.line-input { min-width: 90px; padding: 8px; }
button.remove-line { width: 32px !important; margin: 0 !important; padding: 5px !important; color: #a13636 !important; background: #fff0f0 !important; border-radius: 6px !important; }
.billing-summary>div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; }
.billing-summary .grand-total { margin: 10px 0; padding: 15px 0; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-size: 1.15rem; }
.form-help { margin-top: 12px; color: var(--muted); font-size: .82rem; text-align: center; }

.form-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1/-1; }
.form-grid button { width: auto; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); align-items: end; gap: 14px; }
.filter-grid label { margin-top: 0; }
.filter-grid button { width: auto; margin: 0; }

.login-shell { min-height: calc(100vh - 52px); display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg,#0b132b 0%,#1c2541 52%,#d97706 160%); }
.login-card { width: min(100%,420px); padding: 38px; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
.login-logo { display: block; width: min(240px,80%); max-height: 120px; margin: 0 auto 24px; object-fit: contain; }

.footer {
    padding: 18px;
    color: var(--muted);
    text-align: center;
    font-size: 0.8rem;
    border-top: 1px solid var(--line);
    margin-top: auto;
}

/* ------------------------------------------------------------------------------
   6. RESPONSIVE BREAKPOINTS
   ------------------------------------------------------------------------------ */

@media (max-width: 1200px) {
    .topbar-nav-pills {
        display: none;
    }

    .dashboard-main-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .app-topbar {
        padding: 0 16px;
    }

    .app-body {
        padding: 16px;
    }

    .billing-layout {
        grid-template-columns: 1fr;
    }

    .billing-layout aside {
        position: static;
    }

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

    .user-badge-details {
        display: none;
    }
}
