/* ================================================================
   Eidexas Panel — app.css
   ================================================================ */

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

:root {
    --color-bg:          #f0f2f7;
    --color-sidebar-bg:  #1b1f2a;
    --color-sidebar-txt: #a8b3cf;
    --color-sidebar-act: #ffffff;
    --color-sidebar-hov: rgba(255,255,255,.06);
    --color-accent:      #4f70e8;
    --color-accent-hov:  #3d5dd4;
    --color-surface:     #ffffff;
    --color-border:      #e2e6f0;
    --color-text:        #1b1f2a;
    --color-text-muted:  #7a849e;
    --color-danger:      #e05252;
    --color-success:     #2eb87e;
    --color-warning:     #e09a27;
    --sidebar-w:         220px;
    --topbar-h:          56px;
    --radius:            8px;
    --shadow:            0 1px 4px rgba(0,0,0,.08);
    --shadow-md:         0 4px 16px rgba(0,0,0,.10);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Courier New', monospace; font-size: .85em; }

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

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar__brand-icon {
    font-size: 22px;
    color: var(--color-accent);
}
.sidebar__brand-name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: .01em;
}

.sidebar__nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.sidebar__section {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(168,179,207,.4);
    padding: 14px 8px 4px;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 6px;
    color: var(--color-sidebar-txt);
    font-size: 13.5px;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.sidebar__link:hover { background: var(--color-sidebar-hov); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: var(--color-accent); color: #fff; }
.sidebar__link.is-active .sidebar__link-icon { opacity: 1; }

.sidebar__link--disabled {
    opacity: .45;
    pointer-events: none;
    cursor: default;
}

.sidebar__link-icon { font-size: 15px; opacity: .7; flex-shrink: 0; }

.sidebar__badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    background: rgba(255,255,255,.08);
    color: rgba(168,179,207,.8);
    padding: 2px 6px;
    border-radius: 10px;
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-info strong {
    display: block;
    font-size: 13px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar__user-info small {
    font-size: 11px;
    color: var(--color-sidebar-txt);
    text-transform: capitalize;
}
.sidebar__logout {
    font-size: 18px;
    color: var(--color-sidebar-txt);
    transition: color .15s;
    text-decoration: none;
    line-height: 1;
}
.sidebar__logout:hover { color: var(--color-danger); text-decoration: none; }

/* ── Main content ─────────────────────────────────────────────── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar__title {
    font-size: 17px;
    font-weight: 600;
    color: var(--color-text);
}

.page-content {
    padding: 24px 28px;
    flex: 1;
}

.page-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 18px;
}
.filter-bar {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
}
.card__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
}
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

/* ── Stats row ────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
}
.stat-card--muted { opacity: .6; }

.stat-card__number {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
}
.stat-card__label {
    font-size: 12px;
    color: var(--color-text-muted);
}
.stat-card__hint {
    font-size: 11px;
    color: var(--color-accent);
    margin-top: 4px;
}
.stat-card__link {
    font-size: 11px;
    color: var(--color-text-muted);
    text-decoration: none;
    margin-top: 6px;
    transition: color .15s;
}
.stat-card__link:hover { color: var(--color-accent); }

/* ── Dashboard grid ───────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Quick actions ────────────────────────────────────────────── */
.quick-action {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
    transition: color .15s;
}
.quick-action:last-child { border-bottom: none; }
.quick-action:hover { color: var(--color-accent); text-decoration: none; }
.quick-action strong { display: block; font-size: 13.5px; }
.quick-action small  { font-size: 12px; color: var(--color-text-muted); }

.quick-action__icon {
    width: 36px; height: 36px;
    background: var(--color-bg);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

/* ── Table ────────────────────────────────────────────────────── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.table thead th {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--color-border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: rgba(79,112,232,.03); }
.table td { padding: 11px 16px; vertical-align: middle; }

.table--compact td { padding: 7px 16px; }
.table__th--actions, .table__cell--actions {
    text-align: right;
    white-space: nowrap;
}
.table__cell--muted { color: var(--color-text-muted); font-size: 12px; }
.table__th--num, .table__cell--num { text-align: right; font-variant-numeric: tabular-nums; }
.table__row--total td { background: rgba(79,112,232,.04); border-top: 2px solid var(--color-border); font-weight: 600; }
.table__row--error td { background: rgba(224,82,82,.04); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge--active   { background: #d4f5e8; color: #1a7a53; }
.badge--inactive { background: #fce8e8; color: #a83232; }
.badge--error    { background: #fce8e8; color: #a83232; }
.badge--warn     { background: #fef3cd; color: #856404; }

/* ── Stat card alert ──────────────────────────────────────────── */
.stat-card--alert .stat-card__number { color: var(--color-danger); }

/* ── Accordion ────────────────────────────────────────────────── */
.accordion { display: flex; flex-direction: column; gap: 6px; }

.accordion__item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.accordion__item--error { border-color: #f5c6c6; }

.accordion__header {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 18px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    transition: background .15s;
}
.accordion__header:hover { background: rgba(0,0,0,.02); }
.accordion__header-name  { flex: 1; }

.accordion__chevron {
    font-size: 16px;
    transition: transform .2s;
    color: var(--color-text-muted);
}
.accordion__item.is-open .accordion__chevron { transform: rotate(180deg); }

.accordion__body {
    display: none;
    border-top: 1px solid var(--color-border);
}
.accordion__item.is-open .accordion__body { display: block; }

/* ── Falla message ────────────────────────────────────────────── */
.falla-msg {
    font-size: 12px;
    color: var(--color-danger);
    font-style: italic;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, color .15s, opacity .15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: .65; pointer-events: none; }

.btn--primary  { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn--primary:hover { background: var(--color-accent-hov); border-color: var(--color-accent-hov); }

.btn--ghost    { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
.btn--ghost:hover { background: var(--color-bg); color: var(--color-text); }

.btn--outline  { background: transparent; color: var(--color-accent); border-color: var(--color-accent); }
.btn--outline:hover { background: rgba(79,112,232,.06); }

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

.btn--sm       { padding: 5px 10px; font-size: 12px; }
.btn--full     { width: 100%; justify-content: center; }

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert--success { background: #d4f5e8; color: #14664a; border-color: #a8e6cc; }
.alert--danger,
.alert--error   { background: #fce8e8; color: #8b2020; border-color: #f2b4b4; }
.alert--warning { background: #fef5e1; color: #7a5a00; border-color: #f0d98a; }
.alert--info    { background: #e8effe; color: #2a44a8; border-color: #b4c5f8; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
    padding: 16px 20px;
    color: var(--color-text-muted);
    font-size: 13px;
}
.empty-state--large {
    text-align: center;
    padding: 40px 20px;
}
.empty-state__icon {
    display: block;
    font-size: 32px;
    margin-bottom: 12px;
    opacity: .4;
}

/* ── Card subtitle ────────────────────────────────────────────── */
.card__subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-left: auto;
}

/* ── Quick-access cards (reports index) ───────────────────────── */
.qa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 200px));
    gap: 16px;
}
.qa-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px 16px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    text-decoration: none;
    color: var(--color-text);
    text-align: center;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    transition: all .3s ease;
}
.qa-card:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    transform: translateY(-4px);
    text-decoration: none;
}
.qa-card__icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    margin-bottom: 4px;
}
.qa-card__icon--blue   { background: #dbeafe; color: #2563eb; }
.qa-card__icon--orange { background: #fef3cd; color: #d97706; }
.qa-card__icon--green  { background: #dcfce7; color: #16a34a; }
.qa-card__icon--purple { background: #ede9fe; color: #7c3aed; }
.qa-card__icon--red    { background: #fee2e2; color: #dc2626; }
.qa-card__title { font-size: 13.5px; font-weight: 600; color: var(--color-text); }
.qa-card__desc  { font-size: 12px; color: var(--color-text-muted); line-height: 1.4; }
.qa-card--disabled { opacity: .55; cursor: default; pointer-events: none; }

/* ── Report counters ──────────────────────────────────────────── */
.report-count {
    display: inline-block;
    font-weight: 600;
    font-size: 15px;
    min-width: 32px;
    text-align: right;
}
.report-count--mp   { color: #009ee3; }
.report-count--brou { color: #2eb87e; }

/* ── Log styles ───────────────────────────────────────────────── */
.log-action {
    display: inline-block;
    font-family: 'Courier New', monospace;
    font-size: 11.5px;
    background: var(--color-bg);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--color-text);
}
.log-client {
    font-size: 11.5px;
    color: var(--color-text-muted);
    margin-left: 6px;
}

/* ── Misc ─────────────────────────────────────────────────────── */
.link-external { font-size: 12px; color: var(--color-text-muted); }
.link-external:hover { color: var(--color-accent); }

.slug {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--color-text);
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.form-section {
    padding: 24px;
    border-bottom: 1px solid var(--color-border);
}
.form-section:last-of-type { border-bottom: none; }

.form-section__title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    margin-bottom: 18px;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 640px) {
    .field-row { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field--narrow { max-width: 120px; }

.field__label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 6px;
}
.field__hint {
    font-weight: 400;
    color: var(--color-text-muted);
    font-size: 11px;
}

.field__input {
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 13.5px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
    font-family: inherit;
}
.field__input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(79,112,232,.12);
}
.field--error .field__input { border-color: var(--color-danger); }

.field__textarea { resize: vertical; min-height: 80px; }

.field__error {
    font-size: 12px;
    color: var(--color-danger);
}

.req { color: var(--color-danger); }

.radio-group { display: flex; gap: 20px; }
.radio { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13.5px; }
.radio input { cursor: pointer; accent-color: var(--color-accent); }

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

/* ── Login page ───────────────────────────────────────────────── */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-sidebar-bg);
}

.login-wrap { width: 100%; max-width: 380px; padding: 24px; }

.login-box {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 36px 32px 32px;
    box-shadow: var(--shadow-md);
}

.login-header { text-align: center; margin-bottom: 28px; }
.login-logo {
    display: block;
    font-size: 36px;
    color: var(--color-accent);
    margin-bottom: 12px;
}
.login-title { font-size: 20px; font-weight: 700; color: var(--color-text); margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--color-text-muted); }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form .field { margin-bottom: 0; }

/* ── Sidebar toggle (mobile) ──────────────────────────────────── */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    color: var(--color-text);
    padding: 4px 6px;
    margin-right: 4px;
    flex-shrink: 0;
    line-height: 1;
}

/* ── Sidebar overlay (mobile) ─────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
}
.sidebar-overlay.is-visible { display: block; }

/* ── Table scroll wrapper ─────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ================================================================
   MOBILE — max-width: 768px
   ================================================================ */
@media (max-width: 768px) {

    /* Hamburger */
    .sidebar-toggle { display: flex; }

    /* Sidebar: off-screen by default, slides in */
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-w)));
        transition: transform .25s ease;
    }
    .sidebar.sidebar--open {
        transform: translateX(0);
    }

    /* Main content: full width */
    .main { margin-left: 0; }

    /* Topbar: smaller padding */
    .topbar { padding: 0 16px; }

    /* Page content: less padding */
    .page-content { padding: 16px; }

    /* Stats row: 2 columns */
    .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 16px;
    }
    .stat-card__number { font-size: 22px; }

    /* Dashboard grid: single column */
    .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }

    /* Filter bar: vertical */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    /* Filter form (mp-fallas): stacks on mobile */
    .filter-form {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .filter-form .field__input {
        width: 100% !important;
        margin-right: 0 !important;
    }
    .filter-form .btn { width: 100%; justify-content: center; }

    /* Form sections: less padding */
    .form-section { padding: 16px; }

    /* Form actions: wrap, fill */
    .form-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    .form-actions .btn { flex: 1; justify-content: center; }

    /* Remove narrow constraint on mobile */
    .field--narrow { max-width: none; }

    /* Tables: min-width so they scroll */
    .table-wrap .table { min-width: 480px; }

    /* QA grid: 2 columns on mobile */
    .qa-grid { grid-template-columns: 1fr 1fr; gap: 12px; }

    /* Login box: less padding */
    .login-box { padding: 28px 20px 24px; }

    /* Page actions */
    .page-actions { margin-bottom: 12px; }

    /* Card header wraps */
    .card__header { flex-wrap: wrap; gap: 6px; }
    .card__subtitle { margin-left: 0; }
}
