/**
 * Paddify Admin — app.css
 * Base: Layout, Typography, Buttons, Forms, Utilities
 * SPEC: SPEC-FRONT-ADMIN §3, §6
 * Version: 1.0.0
 *
 * CSS Variables are injected in header_tenant.php per tenant branding.
 */

/* ═══════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--color-text, #1a1a2e);
    background: var(--color-bg, #f8f9fa);
    line-height: 1.5;
    min-height: 100vh;
}

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

img { max-width: 100%; height: auto; }

h1, h2, h3, h4 { line-height: 1.3; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }

/* ═══════════════════════════════════════════
   APP LAYOUT (sidebar + header + main)
   ═══════════════════════════════════════════ */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width, 260px) 1fr;
    grid-template-rows: var(--header-height, 60px) 1fr;
    grid-template-areas:
        "header header"
        "sidebar main";
    min-height: 100vh;
}

.app-layout--plan-banner {
    grid-template-rows: var(--header-height, 60px) var(--plan-banner-height, 44px) 1fr;
    grid-template-areas:
        "header header"
        "banner banner"
        "sidebar main";
}

/* Cintilla Free → upgrade (sticky bajo el header; toda la barra es enlace) */
.plan-upgrade-banner {
    grid-area: banner;
    position: sticky;
    top: var(--header-height, 60px);
    z-index: 95;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: var(--plan-banner-height, 44px);
    padding: 0.55rem 1.5rem;
    background: #0f766e;
    color: #fff;
    font-size: 0.875rem;
    line-height: 1.35;
    text-decoration: none;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}
.plan-upgrade-banner:hover,
.plan-upgrade-banner:focus-visible {
    background: #0d9488;
    color: #fff;
    text-decoration: none;
}
.plan-upgrade-banner:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -2px;
}
.plan-upgrade-banner__text { flex: 1; min-width: 0; }
.plan-upgrade-banner__text strong { font-weight: 700; }
.plan-upgrade-banner__cta {
    flex-shrink: 0;
    font-weight: 600;
    white-space: nowrap;
}

.app-header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    background: var(--color-bg-card, #fff);
    border-bottom: 1px solid var(--color-border, #dee2e6);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
}

.app-header__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1.1rem;
    flex: 1;
}

.app-header__logo {
    height: 32px;
    width: auto;
    border-radius: 4px;
}

.app-header__user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.app-header__name { color: var(--color-text-muted); }

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--color-text);
}

/* Sidebar */
.app-sidebar {
    grid-area: sidebar;
    background: var(--color-secondary, #1A4A7A);
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: sticky;
    top: calc(var(--header-height, 60px) + var(--plan-banner-height, 0px));
    height: calc(100vh - var(--header-height, 60px) - var(--plan-banner-height, 0px));
}

.sidebar-nav { flex: 1; padding: 0.75rem 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: rgba(255,255,255,0.8);
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}

.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }
.nav-item--active { background: rgba(255,255,255,0.15); color: #fff; font-weight: 500; }
.nav-item--locked { opacity: 0.5; }
.nav-item--logout { border-top: 1px solid rgba(255,255,255,0.1); color: rgba(255,255,255,0.6); }
.nav-item--logout:hover { color: #fff; }

.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-icon .icon { width: 20px; height: 20px; }
.nav-lock-icon { width: 12px; height: 12px; opacity: 0.7; margin-left: 2px; }
.nav-badge { background: var(--color-danger); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 0.7rem; }

.nav-group-label {
    padding: 1rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.4);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.8rem;
}

.sidebar-user__name { display: block; font-weight: 500; }
.sidebar-user__role { display: block; color: rgba(255,255,255,0.5); font-size: 0.75rem; }

/* Main content */
.app-main {
    grid-area: main;
    padding: 1.5rem;
    max-width: 1200px;
    width: 100%;
}

.app-main.sidebar-collapsed { max-width: 100%; }

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1.125rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

/* Fallbacks required: login/auth pages do not inject tenant :root vars */
.btn--primary { background: var(--color-primary, #2E75B6); color: #fff; }
.btn--primary:hover { filter: brightness(0.9); }
.btn--danger  { background: var(--color-danger, #dc3545); color: #fff; }
.btn--danger:hover  { filter: brightness(0.9); }
.btn--ghost   { background: transparent; color: var(--color-primary, #2E75B6); border-color: var(--color-border, #dee2e6); }
.btn--ghost:hover { background: var(--color-primary-light, #e8f1f8); }
.btn--full    { width: 100%; }
.btn--sm      { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn--xs      { padding: 0.15rem 0.5rem; font-size: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════ */
.input {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--color-text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(46,117,182,0.12); }
.input--error { border-color: var(--color-danger); }
.input--sm { padding: 0.3rem 0.5rem; font-size: 0.8rem; }
.input--textarea { min-height: 80px; resize: vertical; }
.input--search { max-width: 280px; }

.form-field { margin-bottom: 1rem; }
.form-field--error .form-label { color: var(--color-danger); }
.form-field--inline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 0.25rem; color: var(--color-text); }
.form-required { color: var(--color-danger); margin-left: 2px; }
.form-error { font-size: 0.75rem; color: var(--color-danger); margin-top: 0.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0 1.5rem; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--color-border); }

.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.875rem; }

select.input { appearance: auto; }

/* ═══════════════════════════════════════════
   PAGE LAYOUT
   ═══════════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-subtitle { font-size: 0.875rem; color: var(--color-text-muted); }
.page-actions { display: flex; gap: 0.5rem; align-items: center; }

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

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card__title { font-size: 1rem; font-weight: 600; }

/* ═══════════════════════════════════════════
   ALERTS
   ═══════════════════════════════════════════ */
.alert-container { margin-bottom: 1rem; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.alert--success { background: #d4edda; color: #155724; }
.alert--error   { background: #f8d7da; color: #721c24; }
.alert--warning { background: #fff3cd; color: #856404; }
.alert--info    { background: #d1ecf1; color: #0c5460; }

.alert__close {
    background: none; border: none; cursor: pointer;
    font-size: 1.25rem; color: inherit; opacity: 0.5;
    padding: 0 0.25rem; line-height: 1;
}
.alert__close:hover { opacity: 1; }

/* ═══════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════ */
.text-muted { color: var(--color-text-muted); font-size: 0.875rem; }
.link-sm { font-size: 0.8rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}

.detail-item { padding: 0.5rem 0; }
.detail-label { display: block; font-size: 0.75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-value { font-size: 0.95rem; font-weight: 500; margin-top: 0.15rem; }

.filter-bar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

[x-cloak] { display: none !important; }

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }

    .app-layout--plan-banner {
        grid-template-areas:
            "header"
            "banner"
            "main";
    }

    .sidebar-toggle { display: block; }

    .app-sidebar {
        position: fixed;
        left: -280px;
        top: calc(var(--header-height, 60px) + var(--plan-banner-height, 0px));
        width: 280px;
        z-index: 200;
        transition: left 0.25s ease;
        height: calc(100vh - var(--header-height, 60px) - var(--plan-banner-height, 0px));
    }

    .app-sidebar.is-open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.15); }

    .app-main { padding: 1rem; }

    .plan-upgrade-banner {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.35rem 0.75rem;
    }

    .page-header { flex-direction: column; align-items: flex-start; }
    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .app-header__name { display: none; }
}
