@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Custom Properties ── */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: rgba(30, 30, 50, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.04);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-primary: #e8e8f0;
    --text-secondary: #9a9ab0;
    --text-muted: #6a6a80;
    --accent-blue: #4f8cff;
    --accent-purple: #7c5cff;
    --accent-green: #34d399;
    --accent-orange: #fb923c;
    --accent-red: #f87171;
    --accent-cyan: #22d3ee;
    --gradient-primary: linear-gradient(135deg, #4f8cff 0%, #7c5cff 100%);
    --gradient-card: linear-gradient(135deg, rgba(79, 140, 255, 0.05) 0%, rgba(124, 92, 255, 0.05) 100%);
    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(79, 140, 255, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 2rem;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.sidebar-brand-text {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav { list-style: none; flex: 1; }

.sidebar-nav li { margin-bottom: 0.25rem; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}

.sidebar-nav a:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
    transform: translateX(4px);
}

.sidebar-nav a.active {
    background: rgba(79, 140, 255, 0.12);
    color: var(--accent-blue);
}

.sidebar-nav a .nav-icon { font-size: 1.2rem; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 1rem 0.5rem;
    border-top: 1px solid var(--border-glass);
    margin-top: auto;
}

.sidebar-footer .empresa-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.sidebar-footer .logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-red);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.4rem 0;
    transition: opacity var(--transition);
}

.sidebar-footer .logout-btn:hover { opacity: 0.8; }

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.page-header p { color: var(--text-secondary); font-size: 0.9rem; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    transition: all var(--transition);
}

.card:hover {
    border-color: rgba(79, 140, 255, 0.2);
    box-shadow: var(--shadow-glow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-glass);
}

.card-header h2 { font-size: 1.1rem; font-weight: 600; }

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

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-glass);
}

.data-table td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    vertical-align: middle;
}

.data-table tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-glass); }

/* ── Status Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-created { background: rgba(34, 211, 238, 0.15); color: var(--accent-cyan); }
.badge-processing, .badge-at_terminal { background: rgba(251, 146, 60, 0.15); color: var(--accent-orange); }
.badge-processed, .badge-approved { background: rgba(52, 211, 153, 0.15); color: var(--accent-green); }
.badge-canceled, .badge-rejected { background: rgba(248, 113, 113, 0.15); color: var(--accent-red); }
.badge-refunded { background: rgba(124, 92, 255, 0.15); color: var(--accent-purple); }
.badge-expired { background: rgba(106, 106, 128, 0.15); color: var(--text-muted); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: 0 2px 12px rgba(79, 140, 255, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(79, 140, 255, 0.35);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
}

.btn-secondary:hover { background: rgba(255, 255, 255, 0.08); }

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }

.btn:disabled, .btn.htmx-request {
    opacity: 0.6;
    pointer-events: none;
}

/* ── Forms ── */
.form-group { margin-bottom: 1.25rem; }

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

.form-control {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.1);
}

.form-control::placeholder { color: var(--text-muted); }

/* Select dropdown: options must be dark text on light bg for native OS popup */
select.form-control {
    appearance: auto;
    cursor: pointer;
}

select.form-control option,
select.form-control optgroup {
    background: #fff;
    color: #1a1a2e;
}

select.form-control option:checked {
    background: #e8e8f0;
    color: #0f0f1a;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-blue);
}

/* ── Alerts ── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    animation: fadeSlideIn 0.3s ease-out;
}

.alert-success { background: rgba(52, 211, 153, 0.12); color: var(--accent-green); border: 1px solid rgba(52, 211, 153, 0.2); }
.alert-error { background: rgba(248, 113, 113, 0.12); color: var(--accent-red); border: 1px solid rgba(248, 113, 113, 0.2); }
.alert-info { background: rgba(79, 140, 255, 0.12); color: var(--accent-blue); border: 1px solid rgba(79, 140, 255, 0.2); }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.3s ease-out;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-align: center;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1.5rem;
}

/* ── Webhook Anchor ── */
.webhook-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: rgba(124, 92, 255, 0.1);
    border: 1px solid rgba(124, 92, 255, 0.2);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--accent-purple);
    word-break: break-all;
}

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-glass);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Grid helpers ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ── Side Drawer ── */
.side-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

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

.side-drawer {
    position: fixed;
    top: 0;
    right: -450px;
    width: 100%;
    max-width: 450px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-glass);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: right var(--transition);
    display: flex;
    flex-direction: column;
}

.side-drawer.open {
    right: 0;
}

.side-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-glass);
}

.side-drawer-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* ── Sidebar Accordion ── */
.sidebar-accordion {
    margin-bottom: 0.25rem;
}

.sidebar-accordion-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.sidebar-accordion-toggle:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.sidebar-accordion-toggle.open {
    color: var(--accent-cyan);
}

.sidebar-accordion-toggle .accordion-arrow {
    margin-left: auto;
    font-size: 0.75rem;
    transition: transform var(--transition);
}

.sidebar-accordion-toggle.open .accordion-arrow {
    transform: rotate(90deg);
}

.sidebar-accordion-body {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease;
    opacity: 0;
    padding-left: 0.5rem;
}

.sidebar-accordion-body.open {
    max-height: 500px;
    opacity: 1;
}

.sidebar-accordion-body li {
    margin-bottom: 0.1rem;
}

.sidebar-accordion-body a {
    padding: 0.5rem 0.75rem 0.5rem 1.25rem;
    font-size: 0.85rem;
}

.sidebar-accordion-body a .nav-icon {
    font-size: 1rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
