/* Kopernet OS — admin panel
   Brand palette: PANTONE 2985 C (#1FADE6) · 2394 C (#0096D9) · 2592 C (#8F2182) · 7546 C (#16273B)
   Reference: storage/brand/Kopernet_Manual de Identidad Visual.pdf
   Mobile-first responsive. Type stack: Sora. */

:root {
    /* Brand */
    --brand-cyan:        #1FADE6;
    --brand-blue:        #0096D9;
    --brand-magenta:     #8F2182;
    --brand-navy:        #16273B;
    --brand-navy-2:      #0d1a2c;

    /* Semantic tokens */
    --bg:                #f5f6f8;
    --bg-2:              #ebeef3;
    --card:              #ffffff;
    --ink:               #16273B;
    --ink-strong:        #0d1a2c;
    --muted:             #6b7480;
    --muted-2:           #9aa1ab;
    --border:            #e5e7eb;
    --border-strong:     #d1d5db;

    --accent:            #0096D9;
    --accent-hover:      #007cb5;
    --accent-soft:       #e6f4fb;
    --accent-ink:        #ffffff;

    --magenta:           #8F2182;
    --magenta-soft:      #f7e9f5;

    --danger:            #c0392b;
    --danger-soft:       #fef2f2;

    --success:           #047857;
    --success-soft:      #ecfdf5;

    /* Layout */
    --radius:            12px;
    --radius-sm:         8px;
    --radius-pill:       999px;
    --shadow-sm:         0 1px 2px rgba(15, 23, 42, .06);
    --shadow:            0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .06);
    --shadow-lg:         0 20px 60px rgba(0, 0, 0, .25);
    --transition:        .18s cubic-bezier(.4, 0, .2, 1);

    --font:              'Sora', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    --brand-gradient:    linear-gradient(90deg, var(--brand-cyan) 0%, var(--brand-blue) 45%, var(--brand-magenta) 100%);

    /* Safe areas (iOS) */
    --safe-top:          env(safe-area-inset-top, 0px);
    --safe-bottom:       env(safe-area-inset-bottom, 0px);
    --safe-left:         env(safe-area-inset-left, 0px);
    --safe-right:        env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: underline; }

button, input, textarea { font-family: inherit; }

/* ──────── Topbar ──────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem 1.25rem;
    padding-top: max(.75rem, var(--safe-top));
    padding-left: max(1.25rem, var(--safe-left));
    padding-right: max(1.25rem, var(--safe-right));
    background: var(--brand-navy);
    color: #fff;
    border-bottom: 3px solid transparent;
    border-image: var(--brand-gradient);
    border-image-slice: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.topbar a { color: #fff; opacity: .85; transition: opacity var(--transition); }
.topbar a:hover { opacity: 1; text-decoration: none; }

.brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-shrink: 0;
}
.brand img.logo {
    height: 26px;
    width: auto;
    display: block;
    filter: brightness(0) invert(1);
}
.brand .os-tag {
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, .12);
    padding: .2rem .5rem;
    border-radius: var(--radius-pill);
    color: #fff;
    line-height: 1;
}

.nav {
    display: flex;
    gap: 1.25rem;
    flex: 1;
    margin-left: 1rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
    font-size: .9rem;
    font-weight: 500;
    padding: .35rem 0;
    border-bottom: 2px solid transparent;
    transition: border-color var(--transition);
    white-space: nowrap;
}
.nav a:hover { border-bottom-color: var(--brand-cyan); opacity: 1; }

.userbox {
    display: flex;
    align-items: center;
    gap: .85rem;
    color: rgba(255, 255, 255, .85);
    flex-shrink: 0;
}
.userbox span { font-size: .88rem; }
form.inline { display: inline; margin: 0; }
button.link {
    background: none;
    border: 0;
    color: #fff;
    cursor: pointer;
    padding: .25rem .5rem;
    margin: -.25rem -.5rem;
    font: inherit;
    font-size: .88rem;
    opacity: .8;
    transition: opacity var(--transition);
    min-height: 32px;
}
button.link:hover { opacity: 1; text-decoration: underline; }

/* ──────── Container & layout ──────── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.75rem 1.25rem;
    padding-left: max(1.25rem, var(--safe-left));
    padding-right: max(1.25rem, var(--safe-right));
}
.hero { animation: rise .4s ease-out both; }
.hero h1 {
    margin: 0 0 .25rem;
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--ink-strong);
    letter-spacing: -.01em;
}
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.big {
    font-size: 1.1rem;
    font-weight: 600;
    margin: .5rem 0 .25rem;
    color: var(--ink-strong);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
    animation: rise .5s ease-out both;
}
.card:nth-of-type(1) { animation-delay: .05s; }
.card:nth-of-type(2) { animation-delay: .12s; }
.card:nth-of-type(3) { animation-delay: .19s; }
.card:nth-of-type(4) { animation-delay: .26s; }
.card:hover {
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .08);
    border-color: var(--border-strong);
}
.card h2 {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin: 0 0 .5rem;
    font-weight: 600;
}

.footer {
    text-align: center;
    padding: 2rem 1rem;
    padding-bottom: max(2rem, var(--safe-bottom));
    color: var(--muted);
    font-size: .82rem;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0s !important;
        transition-duration: 0s !important;
    }
}

/* ──────── Login ──────── */
.login-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-navy);
    background-image:
        radial-gradient(ellipse 70% 50% at 50% -10%, rgba(31, 173, 230, .25), transparent 60%),
        radial-gradient(ellipse 60% 40% at 110% 110%, rgba(143, 33, 130, .18), transparent 60%);
    padding: 1.25rem;
    padding-top: max(1.25rem, var(--safe-top));
    padding-bottom: max(1.25rem, var(--safe-bottom));
    padding-left: max(1.25rem, var(--safe-left));
    padding-right: max(1.25rem, var(--safe-right));
}
.login-shell { width: min(400px, 100%); text-align: center; }

.login-card {
    background: var(--card);
    padding: 1.85rem 1.5rem 1.6rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    text-align: left;
    position: relative;
    overflow: hidden;
    animation: rise .5s ease-out both;
}
.login-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--brand-gradient);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    margin: .25rem 0 1rem;
}
.login-logo img {
    height: 36px;
    width: auto;
    display: block;
}
.login-logo .os-tag {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    background: var(--brand-navy);
    color: #fff;
    padding: .22rem .5rem;
    border-radius: var(--radius-pill);
    line-height: 1;
}

.login-card .sub {
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
    margin: 0 0 1.25rem;
}
.login-card label {
    display: block;
    margin-top: .9rem;
    font-size: .78rem;
    color: var(--muted);
    font-weight: 500;
    letter-spacing: .02em;
}
.login-card input[type=email],
.login-card input[type=password] {
    width: 100%;
    padding: .7rem .8rem;
    margin-top: .35rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 16px; /* prevent iOS zoom on focus */
    background: #fff;
    color: var(--ink-strong);
    transition: border-color var(--transition), box-shadow var(--transition);
    min-height: 44px;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

button.primary {
    width: 100%;
    margin-top: 1.4rem;
    background: var(--accent);
    color: var(--accent-ink);
    border: 0;
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:active { transform: scale(.98); }

.alert {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecaca;
    padding: .65rem .8rem;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    font-size: .88rem;
}
.alert.success {
    background: var(--success-soft);
    color: var(--success);
    border-color: #a7f3d0;
}

.login-footer {
    margin-top: 1.25rem;
    color: rgba(255, 255, 255, .55);
    font-size: .72rem;
    letter-spacing: .04em;
}

/* ──────── Conversations list ──────── */
.empty-state {
    background: var(--card);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 2.5rem 1.25rem;
    text-align: center;
    margin-top: 2rem;
    animation: rise .4s ease-out both;
}
.empty-state h2 {
    margin: 0 0 .35rem;
    font-size: 1.05rem;
    color: var(--ink-strong);
    font-weight: 600;
}

.conv-list {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.conv-item {
    display: flex;
    gap: .85rem;
    align-items: flex-start;
    padding: .85rem 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: inherit;
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    min-height: 64px;
    -webkit-tap-highlight-color: transparent;
}
.conv-item:hover, .conv-item:focus-visible {
    border-color: var(--brand-cyan);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.conv-item:active { transform: scale(.995); }
.conv-avatar {
    flex: 0 0 40px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--brand-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    text-transform: uppercase;
}
.conv-body { flex: 1; min-width: 0; }
.conv-row1 {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .15rem;
}
.conv-row1 strong {
    color: var(--ink-strong);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}
.conv-time {
    font-size: .72rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.badge.unread {
    background: var(--accent);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    padding: .12rem .45rem;
    border-radius: var(--radius-pill);
    line-height: 1.3;
    flex-shrink: 0;
}
.conv-preview {
    color: var(--ink);
    font-size: .92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}
.conv-meta {
    font-size: .72rem;
    margin-top: .15rem;
}

/* ──────── Chat view ──────── */
.conv-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
    animation: rise .35s ease-out both;
}
.conv-header .back {
    margin-top: .35rem;
    font-size: .9rem;
    flex-shrink: 0;
    padding: .35rem .5rem;
    margin-left: -.5rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.conv-header .back:hover {
    background: var(--bg-2);
    text-decoration: none;
}
.conv-title { flex: 1; min-width: 0; }
.conv-title h1 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--ink-strong);
    font-weight: 600;
    letter-spacing: -.005em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-title p { margin: .15rem 0 0; font-size: .82rem; }

.chat {
    background: var(--card);
    background-image:
        radial-gradient(circle at 25% 10%, rgba(31, 173, 230, .035) 0%, transparent 40%),
        radial-gradient(circle at 75% 90%, rgba(143, 33, 130, .025) 0%, transparent 40%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 50vh;
    max-height: 65vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    scroll-behavior: smooth;
}
.chat .center { text-align: center; padding: 2rem 0; margin: auto; }

.bubble {
    max-width: 78%;
    padding: .65rem .85rem;
    border-radius: 16px;
    font-size: .94rem;
    line-height: 1.45;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    animation: bubble-in .25s ease-out both;
}
.bubble.in {
    align-self: flex-start;
    background: #f0f3f7;
    color: var(--ink-strong);
    border-bottom-left-radius: 4px;
}
.bubble.out {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble.out.sender-bot { background: var(--brand-navy); }
.bubble-body { white-space: pre-wrap; }
.bubble-meta {
    margin-top: .3rem;
    font-size: .68rem;
    opacity: .75;
    letter-spacing: .02em;
}
.bubble.out .bubble-meta { color: rgba(255,255,255,.85); }
.bubble.out .muted { color: rgba(255,255,255,.7); }

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.reply-form {
    margin-top: 1rem;
    display: flex;
    gap: .5rem;
    align-items: flex-end;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .55rem;
    box-shadow: var(--shadow-sm);
}
.reply-form textarea {
    flex: 1;
    padding: .6rem .75rem;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 16px;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    color: var(--ink-strong);
}
.reply-form textarea:focus { outline: none; }
.reply-form button.primary {
    width: auto;
    margin-top: 0;
    padding: .6rem 1.25rem;
    flex-shrink: 0;
}

a.back { color: var(--muted); font-size: .9rem; }
a.back:hover { color: var(--accent); text-decoration: none; }

/* ──────── Responsive: tablet ──────── */
@media (max-width: 900px) {
    .container { padding: 1.5rem 1rem; }
    .hero h1 { font-size: 1.4rem; }
    .grid { gap: .85rem; }
}

/* ──────── Responsive: mobile ──────── */
@media (max-width: 640px) {
    .topbar {
        flex-wrap: wrap;
        gap: .5rem 1rem;
        padding: .65rem .9rem;
        padding-top: max(.65rem, var(--safe-top));
        padding-left: max(.9rem, var(--safe-left));
        padding-right: max(.9rem, var(--safe-right));
    }
    .brand img.logo { height: 22px; }
    .brand .os-tag { font-size: .6rem; padding: .15rem .4rem; }
    .nav {
        order: 3;
        flex-basis: 100%;
        margin-left: 0;
        margin-top: .35rem;
        padding-bottom: .15rem;
        gap: 1rem;
        border-top: 1px solid rgba(255, 255, 255, .08);
        padding-top: .55rem;
    }
    .nav a { font-size: .85rem; }
    .userbox { gap: .55rem; }
    .userbox span {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .container { padding: 1.25rem .85rem; }
    .hero h1 { font-size: 1.3rem; }

    .grid { grid-template-columns: 1fr; margin-top: 1.5rem; }

    .conv-list { gap: .4rem; margin-top: 1.25rem; }
    .conv-item { padding: .75rem .85rem; }
    .conv-time { font-size: .68rem; }
    .conv-meta { display: none; }

    .conv-header { margin-bottom: .75rem; }
    .conv-title h1 { font-size: 1.15rem; }
    .chat {
        min-height: calc(100dvh - 290px);
        max-height: calc(100dvh - 270px);
        padding: .75rem;
    }
    .bubble { max-width: 85%; font-size: .92rem; }
    .reply-form {
        position: sticky;
        bottom: max(0px, var(--safe-bottom));
        margin-bottom: calc(-1 * var(--safe-bottom));
        z-index: 10;
    }

    .login-card { padding: 1.5rem 1.25rem 1.4rem; }
    .login-logo img { height: 32px; }

    .empty-state { padding: 1.75rem 1rem; }
}

/* ──────── Responsive: very small (≤360px) ──────── */
@media (max-width: 360px) {
    .brand .os-tag { display: none; }
    .userbox span { max-width: 60px; }
}

/* ──────── Touch / pointer adjustments ──────── */
@media (hover: none) {
    .conv-item:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
    .card:hover { box-shadow: var(--shadow); border-color: var(--border); }
}

/* ──────── Print ──────── */
@media print {
    .topbar, .reply-form, .footer, .conv-header .back { display: none !important; }
    body { background: white; }
}
