/* ==========================================================================
   Random Tools — Sistema de diseño compartido
   Un solo lugar para tokens, layout de app (sidebar + topbar) y componentes.
   Todas las herramientas consumen este archivo.
   ========================================================================== */

/* --- Tokens -------------------------------------------------------------- */
:root {
    color-scheme: dark;

    --bg: #08080b;
    --bg-blur: rgba(8, 8, 11, .78);
    --rail: #0d0d11;
    --surface: #141419;
    --surface-2: #1a1a21;
    --surface-3: #22222a;
    --line: rgba(255, 255, 255, .07);
    --line-2: rgba(255, 255, 255, .14);

    --tx: #f3f3f5;
    --tx-2: #9a9aa5;
    --tx-3: #6a6a75;

    --pri: #ffffff;
    --pri-tx: #0a0a0d;

    --mint: #7ee7bb;
    --mint-bg: rgba(126, 231, 187, .13);
    --violet: #b9a6ff;
    --violet-bg: rgba(185, 166, 255, .13);
    --amber: #ffcf7a;
    --amber-bg: rgba(255, 207, 122, .13);
    --sky: #8ec5ff;
    --sky-bg: rgba(142, 197, 255, .13);
    --rose: #ff9db2;
    --rose-bg: rgba(255, 157, 178, .13);

    --r-xl: 24px;
    --r-lg: 18px;
    --r-md: 12px;
    --r-sm: 9px;

    --shadow: 0 24px 48px -32px rgba(0, 0, 0, .95);
    --rail-w: 264px;

    --ff: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
    --ff-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
    color-scheme: light;

    --bg: #f1f1f4;
    --bg-blur: rgba(241, 241, 244, .82);
    --rail: #ffffff;
    --surface: #ffffff;
    --surface-2: #f5f5f8;
    --surface-3: #eaeaef;
    --line: rgba(15, 15, 25, .09);
    --line-2: rgba(15, 15, 25, .18);

    --tx: #14141a;
    --tx-2: #5f5f6c;
    --tx-3: #8d8d99;

    --pri: #14141a;
    --pri-tx: #ffffff;

    --mint: #0f9d6e;
    --mint-bg: rgba(15, 157, 110, .12);
    --violet: #6d51d8;
    --violet-bg: rgba(109, 81, 216, .12);
    --amber: #b57614;
    --amber-bg: rgba(181, 118, 20, .12);
    --sky: #1f6fd0;
    --sky-bg: rgba(31, 111, 208, .12);
    --rose: #c8425f;
    --rose-bg: rgba(200, 66, 95, .12);

    --shadow: 0 18px 40px -30px rgba(20, 20, 40, .45);
}

/* --- Reset --------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--tx);
    font-family: var(--ff);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

h1, h2, h3, h4, p, figure {
    margin: 0;
}

/* `hidden` debe ganarle a cualquier display de componente (.studio usa grid) */
[hidden] {
    display: none !important;
}

a {
    color: inherit;
    text-decoration: none;
}

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

::selection {
    background: var(--tx);
    color: var(--bg);
}

:focus-visible {
    outline: 2px solid var(--line-2);
    outline-offset: 2px;
}

::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 99px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--line-2);
    background-clip: padding-box;
}

/* --- Iconos -------------------------------------------------------------- */
.icon {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon--sm { width: 13px; height: 13px; }
.icon--lg { width: 19px; height: 19px; }
.icon--xl { width: 22px; height: 22px; }

/* --- Layout de aplicación ------------------------------------------------ */
.app {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Para páginas tipo "app": la altura queda fija al viewport y el scroll ocurre
   dentro de los paneles, no en el documento. */
.main--fixed {
    height: 100vh;
    overflow: hidden;
}

.content {
    flex: 1;
    min-height: 0;
    padding: 24px 26px 34px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.content--flush {
    padding-bottom: 26px;
}

/* --- Sidebar ------------------------------------------------------------- */
.rail {
    width: var(--rail-w);
    flex: 0 0 var(--rail-w);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 14px;
    background: var(--rail);
    border-right: 1px solid var(--line);
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--r-lg);
    background: var(--surface);
    border: 1px solid var(--line);
    transition: border-color .18s ease;
}

.brand:hover { border-color: var(--line-2); }

.brand__avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    color: #0a0a0d;
    background: linear-gradient(140deg, #ffd9a8, #b9a6ff 55%, #7ee7bb);
}

.brand__meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.brand__meta strong {
    font-size: 12.5px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand__meta small {
    font-size: 10.5px;
    color: var(--tx-3);
}

.brand .pill { margin-left: auto; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    flex: 1 1 auto;
    margin: 0 -4px;
    padding: 0 4px;
}

.nav__label {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--tx-3);
    padding: 14px 12px 6px;
}

.nav__label:first-child { padding-top: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: none;
    color: var(--tx-2);
    font-size: 12.8px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease, border-color .16s ease;
}

.nav-item:hover {
    color: var(--tx);
    background: var(--surface);
}

.nav-item.is-active {
    color: var(--tx);
    background: var(--surface-2);
    border-color: var(--line);
    font-weight: 600;
}

.nav-item__hint {
    margin-left: auto;
    font-size: 10px;
    color: var(--tx-3);
}

.nav-item.is-active .nav-item__hint { color: var(--tx-2); }

.promo {
    position: relative;
    overflow: hidden;
    border-radius: var(--r-lg);
    border: 1px solid var(--line);
    background:
        radial-gradient(120% 90% at 15% 0%, rgba(185, 166, 255, .16), transparent 60%),
        var(--surface);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.promo__badge {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--violet);
}

.promo strong {
    font-size: 12.5px;
    font-weight: 650;
    line-height: 1.35;
}

.promo p {
    font-size: 10.8px;
    color: var(--tx-3);
    line-height: 1.45;
}

/* --- Topbar -------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 26px;
    background: var(--bg-blur);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}

.crumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tx-3);
    min-width: 0;
}

.crumb b {
    color: var(--tx);
    font-weight: 600;
}

.topbar__spacer { flex: 1 1 auto; }

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.rail-toggle { display: none; }

/* --- Encabezado de página ------------------------------------------------ */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 6px 0 2px;
}

.page-head h1 {
    font-size: 27px;
    font-weight: 640;
    letter-spacing: -.025em;
    line-height: 1.15;
}

.page-head p {
    font-size: 12.5px;
    color: var(--tx-2);
    margin-top: 5px;
}

/* --- Buscador ------------------------------------------------------------ */
.search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 13px;
    min-width: 190px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--tx-3);
    transition: border-color .18s ease;
}

.search:focus-within { border-color: var(--line-2); }

.search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    outline: none;
    font-size: 12.5px;
    color: var(--tx);
}

.search input::placeholder { color: var(--tx-3); }

/* --- Botones ------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 36px;
    padding: 0 15px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--tx);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: transform .16s ease, border-color .16s ease, background-color .16s ease, opacity .16s ease;
}

.btn:hover {
    border-color: var(--line-2);
    transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn--primary {
    background: var(--pri);
    color: var(--pri-tx);
    border-color: transparent;
}

.btn--primary:hover { opacity: .88; }

.btn--soft { background: var(--surface-2); }

.btn--ghost {
    background: transparent;
    color: var(--tx-2);
}

.btn--ghost:hover { color: var(--tx); }

.btn--mint { background: var(--mint-bg); color: var(--mint); border-color: transparent; }
.btn--violet { background: var(--violet-bg); color: var(--violet); border-color: transparent; }
.btn--sky { background: var(--sky-bg); color: var(--sky); border-color: transparent; }

.btn--icon {
    width: 36px;
    padding: 0;
}

.btn--sm {
    height: 30px;
    padding: 0 12px;
    font-size: 11.5px;
    gap: 6px;
}

.btn--sm.btn--icon { width: 30px; }

.btn[disabled] {
    opacity: .45;
    pointer-events: none;
}

/* --- Segmentado (tabs) --------------------------------------------------- */
.seg {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.seg__btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 28px;
    padding: 0 13px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--tx-2);
    font-size: 11.8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease;
}

.seg__btn:hover { color: var(--tx); }

.seg__btn.is-active {
    background: var(--pri);
    color: var(--pri-tx);
}

/* --- Píldoras / badges --------------------------------------------------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 21px;
    padding: 0 9px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--tx-2);
    font-size: 10.3px;
    font-weight: 650;
    letter-spacing: .01em;
    white-space: nowrap;
}

.pill--mint { background: var(--mint-bg); color: var(--mint); }
.pill--violet { background: var(--violet-bg); color: var(--violet); }
.pill--amber { background: var(--amber-bg); color: var(--amber); }
.pill--sky { background: var(--sky-bg); color: var(--sky); }
.pill--rose { background: var(--rose-bg); color: var(--rose); }

.pill--mono {
    font-family: var(--ff-mono);
    font-size: 10px;
    font-weight: 500;
}

/* --- Tarjetas ------------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    padding: 20px;
    min-width: 0;
}

.card--pad-sm { padding: 16px; }

.card--flat { background: var(--surface-2); }

.card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.card__title {
    font-size: 13.5px;
    font-weight: 650;
    letter-spacing: -.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card__sub {
    font-size: 11.5px;
    color: var(--tx-2);
    margin-top: 3px;
}

.card__tools {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.tile-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--tx-2);
}

.tile-icon--mint { background: var(--mint-bg); color: var(--mint); border-color: transparent; }
.tile-icon--violet { background: var(--violet-bg); color: var(--violet); border-color: transparent; }
.tile-icon--sky { background: var(--sky-bg); color: var(--sky); border-color: transparent; }
.tile-icon--amber { background: var(--amber-bg); color: var(--amber); border-color: transparent; }

/* --- Campos de formulario ------------------------------------------------ */
.field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 11px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--tx-2);
    font-size: 11.5px;
    font-weight: 500;
}

.field > label {
    white-space: nowrap;
    cursor: default;
}

.input {
    height: 34px;
    padding: 0 12px;
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--tx);
    font-size: 12.5px;
    font-weight: 500;
    outline: none;
    transition: border-color .16s ease;
}

.input:focus { border-color: var(--line-2); }

.input::placeholder { color: var(--tx-3); }

select.input,
.field select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 26px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9aa5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 13px;
    cursor: pointer;
}

.field select {
    height: 26px;
    border: 0;
    border-radius: var(--r-sm);
    background-color: transparent;
    color: var(--tx);
    font-size: 11.5px;
    font-weight: 600;
    padding: 0 22px 0 4px;
    outline: none;
}

select option {
    background: var(--surface);
    color: var(--tx);
}

/* Checkbox */
.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--tx-2);
    cursor: pointer;
    transition: border-color .16s ease, color .16s ease;
    user-select: none;
}

.check:hover { border-color: var(--line-2); }

.check input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.check__box {
    width: 15px;
    height: 15px;
    border-radius: 5px;
    border: 1px solid var(--line-2);
    display: grid;
    place-items: center;
    transition: background-color .16s ease, border-color .16s ease;
}

.check__box::after {
    content: "";
    width: 7px;
    height: 4px;
    border-left: 1.8px solid var(--pri-tx);
    border-bottom: 1.8px solid var(--pri-tx);
    transform: rotate(-45deg) scale(.4);
    opacity: 0;
    transition: .16s ease;
}

.check input:checked + .check__box {
    background: var(--pri);
    border-color: var(--pri);
}

.check input:checked + .check__box::after {
    opacity: 1;
    transform: rotate(-45deg) scale(1);
}

.check input:checked ~ span { color: var(--tx); }

.check input:focus-visible + .check__box {
    outline: 2px solid var(--line-2);
    outline-offset: 2px;
}

/* --- Tablas -------------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    margin: 0 -6px;
    padding: 0 6px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.table th {
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--tx-3);
    padding: 0 14px 11px;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}

.table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--tx-2);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr {
    transition: background-color .16s ease;
}

.table tbody tr:hover { background: var(--surface-2); }

.table .td-strong {
    color: var(--tx);
    font-weight: 600;
}

.table .td-right { text-align: right; }

.table--mono tbody td {
    font-family: var(--ff-mono);
    font-size: 11.5px;
}

.table--sticky thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

/* --- Modal --------------------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, .62);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.modal[hidden] { display: none; }

.modal__panel {
    width: 100%;
    max-width: 720px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: pop .18s ease;
}

.modal__panel--wide { max-width: 1000px; }

@keyframes pop {
    from { opacity: 0; transform: translateY(8px) scale(.99); }
    to { opacity: 1; transform: none; }
}

.modal__head,
.modal__foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
}

.modal__head { border-bottom: 1px solid var(--line); }

.modal__foot {
    border-top: 1px solid var(--line);
    justify-content: space-between;
}

.modal__head h3 {
    font-size: 13.5px;
    font-weight: 650;
    display: flex;
    align-items: center;
    gap: 9px;
}

.modal__head .btn { margin-left: auto; }

.modal__body {
    padding: 18px 20px;
    overflow: auto;
    flex: 1;
}

.modal__body--flush { padding: 0; }

.modal__note {
    font-size: 11.5px;
    color: var(--tx-3);
}

/* --- Toast --------------------------------------------------------------- */
.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 120;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 16px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line-2);
    box-shadow: var(--shadow);
    font-size: 12px;
    font-weight: 550;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}

.toast.is-open {
    opacity: 1;
    transform: none;
}

.toast .icon { color: var(--mint); }

/* --- Utilidades ---------------------------------------------------------- */
.grid { display: grid; gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.muted { color: var(--tx-2); }
.dim { color: var(--tx-3); }
.mono { font-family: var(--ff-mono); }
.text-xs { font-size: 11.5px; }
.text-sm { font-size: 12.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sep { height: 1px; background: var(--line); border: 0; margin: 0; }
/* .hide-sm no declara `display` en su estado visible: si lo hiciera, un <td>
   pasaría a ser inline y rompería la tabla. Sólo se oculta en pantallas chicas. */

.stat {
    font-size: 26px;
    font-weight: 650;
    letter-spacing: -.03em;
    line-height: 1;
}

.empty {
    padding: 30px 12px;
    text-align: center;
    color: var(--tx-3);
    font-size: 12.5px;
}

kbd {
    font-family: var(--ff-mono);
    font-size: 10.5px;
    padding: 3px 7px;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--tx);
    white-space: nowrap;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tx-3);
    flex: 0 0 auto;
}

.dot--live {
    background: var(--mint);
    animation: pulse 1.9s ease-in-out infinite;
}

@keyframes pulse {
    50% { opacity: .35; }
}

.scrim {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, .5);
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 1080px) {
    .hide-sm { display: none !important; }
}

@media (max-width: 900px) {
    .rail {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-101%);
        transition: transform .22s ease;
        box-shadow: var(--shadow);
    }

    .app.rail-open .rail { transform: none; }
    .app.rail-open .scrim { display: block; }
    .rail-toggle { display: inline-flex; }

    .topbar { padding: 12px 16px; }
    .content { padding: 18px 16px 26px; }
    .page-head h1 { font-size: 22px; }
    .search { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}
