:root {
    --ink: #152033;
    --ink-muted: #66758b;
    --paper: #f7f8fb;
    --surface: #ffffff;
    --line: #e7ebf2;
    --cyan: #12c4a8;
    --cyan-deep: #0aa890;
    --cyan-soft: #e7faf6;
    --coral: #ef5b6e;
    --coral-soft: #ffe8ec;
    --amber: #f0a202;
    --sky: #3b8bed;
    --violet: #6d6af0;
    --card: #ffffff;
    --shadow: 0 10px 28px rgba(21, 32, 51, 0.06);
    --radius: 16px;
    --font: "Outfit", system-ui, sans-serif;
    --display: "Space Grotesk", "Outfit", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
}

h1, h2, h3, h4, .brand-mark {
    font-family: var(--display);
}

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    overflow: hidden;
    position: relative;
    background: #07101f;
    color: #fff;
}

.login-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(8px);
    animation: floaty 10s ease-in-out infinite;
}

.orb-a {
    width: 42vw;
    height: 42vw;
    left: -10%;
    top: -15%;
    background: radial-gradient(circle, rgba(32, 227, 194, 0.55), transparent 70%);
}

.orb-b {
    width: 36vw;
    height: 36vw;
    right: -8%;
    top: 20%;
    background: radial-gradient(circle, rgba(255, 93, 108, 0.45), transparent 70%);
    animation-delay: -3s;
}

.orb-c {
    width: 28vw;
    height: 28vw;
    left: 35%;
    bottom: -12%;
    background: radial-gradient(circle, rgba(77, 163, 255, 0.4), transparent 70%);
    animation-delay: -6s;
}

@keyframes floaty {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-18px) scale(1.04); }
}

.login-shell {
    position: relative;
    z-index: 1;
    width: min(980px, calc(100% - 2rem));
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 1.5rem;
    align-items: stretch;
}

.login-brand {
    padding: 2.5rem 1rem 2.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.brand-mark {
    display: inline-block;
    width: fit-content;
    margin: 0 0 1rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--cyan), var(--sky));
    color: #041018;
    font-weight: 700;
    letter-spacing: 0.02em;
    animation: pulseSoft 2.8s ease-in-out infinite;
}

.login-brand h1 {
    margin: 0 0 1rem;
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
    font-weight: 700;
}

.brand-lead {
    margin: 0;
    max-width: 28rem;
    color: rgba(255, 255, 255, 0.72);
    font-size: 1.05rem;
    line-height: 1.5;
}

.login-card {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(18px);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: var(--shadow);
    animation: riseIn 0.7s ease both;
}

.login-card h2 {
    margin: 0;
    font-size: 1.65rem;
}

.login-sub {
    margin: 0.35rem 0 1.4rem;
    color: rgba(255, 255, 255, 0.65);
}

.alert-login {
    background: rgba(255, 93, 108, 0.18);
    border: 1px solid rgba(255, 93, 108, 0.45);
    color: #ffd7db;
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.login-form {
    display: grid;
    gap: 1rem;
}

.field {
    display: grid;
    gap: 0.4rem;
}

.field span {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.field input {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(7, 16, 31, 0.55);
    color: #fff;
    border-radius: 12px;
    padding: 0.85rem 1rem;
    font: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(32, 227, 194, 0.25);
}

.btn-login {
    margin-top: 0.4rem;
    border: 0;
    border-radius: 14px;
    padding: 0.95rem 1.2rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    color: #041018;
    background: linear-gradient(120deg, var(--cyan) 0%, var(--sky) 55%, #7ad7ff 100%);
    background-size: 160% 160%;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: shimmer 5s ease infinite;
}

.btn-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(32, 227, 194, 0.35);
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes riseIn {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseSoft {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* ---------- Sidebar (claro) ---------- */
.sidebar {
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    padding: 1.25rem 0.9rem;
    background: var(--surface);
    border-right: 1px solid var(--line);
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    z-index: 20;
}

.sidebar-brand {
    margin: 0 0.35rem 1.1rem;
    padding: 0.95rem 0.9rem;
    border-radius: 14px;
    background: var(--cyan-soft);
    border: 1px solid #d7f3ec;
}

.sidebar-brand .title {
    margin: 0;
    color: var(--ink);
    font-family: var(--display);
    font-size: 1.15rem;
    font-weight: 700;
}

.sidebar-brand .subtitle {
    margin: 0.25rem 0 0;
    color: var(--ink-muted);
    font-size: 0.8rem;
}

.sidebar-project {
    display: flex !important;
    align-items: center;
    gap: 0.7rem;
    margin: 0 0.15rem 0.85rem;
    padding: 0.65rem 0.7rem !important;
    border-radius: 14px !important;
    background: #f4f7fb;
    border: 1px solid var(--line);
    text-decoration: none !important;
    color: var(--ink) !important;
}

.sidebar-project:hover {
    background: #eef3f9 !important;
    color: var(--ink) !important;
}

.sidebar-project-thumb,
.sidebar-project-fallback {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    flex-shrink: 0;
    object-fit: cover;
}

.sidebar-project-thumb.is-fallback {
    display: none;
}

.sidebar-project-fallback {
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    background: linear-gradient(135deg, #12c4a8, #3b8bed);
}

.sidebar-project-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sidebar-project-meta strong {
    font-size: 0.92rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-project-meta small {
    color: var(--ink-muted);
    font-family: ui-monospace, monospace;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
}

.sidebar a {
    color: #3d4d63;
    text-decoration: none;
    padding: 0.72rem 0.95rem;
    display: block;
    border-radius: 12px;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar a:hover {
    background: #f2f5f9;
    color: var(--ink);
}

.sidebar a.active {
    background: var(--cyan-soft);
    color: var(--cyan-deep);
    box-shadow: inset 3px 0 0 var(--cyan);
    font-weight: 600;
}

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

.sidebar-user {
    color: var(--ink-muted);
    font-size: 0.85rem;
    padding: 0.4rem 0.95rem 0.7rem;
}

.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.7rem;
    margin-bottom: 0.45rem;
    border-radius: 12px;
    text-decoration: none !important;
    color: inherit;
    background: #f4f7fb;
}

.sidebar-profile:hover {
    background: #eaf2f8;
    transform: none;
}

.sidebar-avatar,
.sidebar-avatar-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-avatar-fallback {
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #12c4a8, #3b8bed);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
}

.sidebar-profile .sidebar-user {
    padding: 0;
    line-height: 1.2;
    color: var(--ink);
    font-weight: 600;
}

.sidebar-profile .sidebar-user small {
    display: block;
    margin-top: 0.15rem;
    color: var(--ink-muted);
    font-weight: 500;
    font-family: ui-monospace, monospace;
    font-size: 0.72rem;
}

.profile-avatar-wrap {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #e7ebf2;
    background: #f4f7fb;
}

.profile-avatar-wrap img,
.profile-avatar-fallback {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar-fallback {
    display: grid;
    place-items: center;
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #12c4a8, #3b8bed);
}

.crop-stage {
    max-height: 60vh;
    background: #111827;
    border-radius: 12px;
    overflow: hidden;
}

.crop-stage img {
    display: block;
    max-width: 100%;
}

.cropper-view-box,
.cropper-face {
    border-radius: 50%;
}

.sidebar a.logout-link {
    background: var(--coral-soft);
    color: #c53b4e;
}

.sidebar a.logout-link:hover {
    background: #ffd6dd;
    color: #9f2436;
}

.main-content {
    margin-left: 280px;
    padding: 1.75rem 1.75rem 2.5rem;
    min-height: 100vh;
    background: var(--paper);
}

.page-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-hero h2 {
    margin: 0;
    font-size: clamp(1.6rem, 2.4vw, 2.1rem);
}

.page-hero p {
    margin: 0.35rem 0 0;
    color: #53627a;
}

.btn-primary,
.btn.btn-primary {
    background: var(--cyan-deep) !important;
    border: 0 !important;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(10, 168, 144, 0.2);
}

.btn-success,
.btn.btn-success {
    background: #12b886 !important;
    border: 0 !important;
}

.btn-warning,
.btn.btn-warning {
    background: var(--amber) !important;
    border: 0 !important;
    color: #1b1408 !important;
}

.btn-danger,
.btn.btn-danger {
    background: var(--coral) !important;
    border: 0 !important;
}

.project-card,
.card {
    border: 1px solid var(--line) !important;
    border-radius: var(--radius) !important;
    overflow: hidden;
    background: var(--card) !important;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.project-card:hover,
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 32px rgba(21, 32, 51, 0.1);
    border-color: #d5dce8 !important;
}

.project-card .card-img-top {
    width: 100%;
    height: 160px;
    max-width: 100%;
    object-fit: cover;
    object-position: center;
    background: linear-gradient(135deg, #d9f6ef, #dce9fb);
}

.project-card .card-body {
    padding: 1.15rem 1.2rem 1.3rem;
}

/* Tarjetas compactas de proyectos */
.project-card-mini {
    display: flex;
    gap: 0.85rem;
    align-items: stretch;
    min-height: 112px;
    padding: 0.7rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 6px 18px rgba(21, 32, 51, 0.05);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.project-card-mini:hover {
    transform: translateY(-2px);
    border-color: #cfe3de;
    box-shadow: 0 10px 24px rgba(21, 32, 51, 0.08);
}

.project-card-mini-media {
    width: 72px;
    min-width: 72px;
    height: 72px;
    border-radius: 10px;
    overflow: hidden;
    background: linear-gradient(135deg, #d9f6ef, #dce9fb);
}

.project-card-mini-media img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.project-card-mini-media img.is-fallback {
    opacity: 0.35;
    object-fit: cover;
}

.project-image-preview {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.75rem;
    background: #f8fafc;
}

.project-image-preview img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 180px;
    border-radius: 8px;
    object-fit: cover;
    object-position: center;
}

.project-card-mini-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.project-card-mini-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.project-card-mini-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-role {
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    padding: 0.18rem 0.45rem;
    border-radius: 999px;
}

.project-role.is-owner {
    background: #e7faf6;
    color: #0aa890;
}

.project-role.is-guest {
    background: #eef3ff;
    color: #3b8bed;
}

.project-card-mini-code {
    margin: 0.2rem 0 0;
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.project-card-mini-code code {
    color: var(--cyan-deep);
    font-size: 0.75rem;
}

.project-card-mini-desc {
    margin: 0.25rem 0 0.55rem;
    font-size: 0.8rem;
    color: #617089;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.1em;
}

.project-card-mini-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: auto;
}

.project-card-mini-actions .btn {
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--ink);
    min-height: 160px;
    box-shadow: var(--shadow);
    background: var(--surface);
}

.stat-card .card-body {
    padding: 1.25rem;
}

.stat-card.tone-users {
    background: linear-gradient(165deg, #ffffff 55%, #e7faf6 100%);
    border-top: 3px solid var(--cyan);
}

.stat-card.tone-cats {
    background: linear-gradient(165deg, #ffffff 55%, #ebeafc 100%);
    border-top: 3px solid var(--violet);
}

.stat-card.tone-keys {
    background: linear-gradient(165deg, #ffffff 55%, #fff4df 100%);
    border-top: 3px solid var(--amber);
}

.stat-card.tone-logs {
    background: linear-gradient(165deg, #ffffff 55%, #ffe8ec 100%);
    border-top: 3px solid var(--coral);
}

.stat-card.tone-events {
    background: linear-gradient(165deg, #ffffff 55%, #e8f1ff 100%);
    border-top: 3px solid var(--sky);
}

.stat-card.tone-monitor {
    background: linear-gradient(165deg, #ffffff 55%, #e7faf6 100%);
    border-top: 3px solid var(--cyan-deep);
}

.stat-card.warn {
    outline: 2px solid rgba(239, 91, 110, 0.35);
}

.stat-card .card-title {
    font-family: var(--display);
    font-weight: 700;
    color: var(--ink);
}

.stat-card .card-text {
    color: var(--ink-muted);
}

.table {
    background: var(--surface);
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--line);
}

.modal-content {
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.filters-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem 1.2rem;
    box-shadow: var(--shadow);
}

.stat-card-link:hover {
    text-decoration: none;
    color: inherit;
}

.stat-card-link .stat-card {
    cursor: pointer;
    height: 100%;
}

.stat-card-cta {
    display: inline-block;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--cyan-deep);
}

.stat-card-link:hover .stat-card-cta {
    text-decoration: underline;
}

.kpi-card .kpi-label {
    color: var(--ink-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.kpi-card strong {
    font-family: var(--display);
    font-size: 1.65rem;
    color: var(--ink);
    line-height: 1.1;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.15rem 1.2rem 1.3rem;
    box-shadow: var(--shadow);
    height: 100%;
}

.chart-card h3 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.integrate-guide .integrate-steps {
    padding-left: 1.2rem;
}

.integrate-guide .integrate-steps li {
    margin-bottom: 0.45rem;
    color: var(--ink-muted);
}

.integrate-guide .integrate-steps a {
    color: var(--cyan-deep);
    font-weight: 600;
}

.integrate-box {
    height: 100%;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: #f4f7fb;
    border: 1px solid var(--line);
}

.integrate-box h4 {
    margin: 0 0 0.45rem;
    font-size: 0.85rem;
    font-weight: 700;
}

.integrate-code-inline {
    display: block;
    word-break: break-all;
    font-size: 0.8rem;
}

.integrate-table code {
    color: var(--cyan-deep);
}

.integrate-code-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    background: #0f172a;
    color: #e2e8f0;
}

.integrate-code {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #dbeafe;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.json-viewer {
    margin: 0;
    max-height: 320px;
    overflow: auto;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    border: 1px solid #1e293b;
    background: #0f172a;
    color: #f8fafc;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.82rem;
    line-height: 1.5;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

    .login-brand {
        padding: 1rem 0 0;
        text-align: center;
        align-items: center;
    }

    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
    }

    .main-content {
        margin-left: 0;
        padding: 1.25rem;
    }
}
