/* Spells — paleta slate alinhada com monsters/tasks. Reusa o pattern Cinzel
   + IM Fell + ornamentos. JS continua selecionando .spells-page, .spells-tabs,
   .spells-tab-button, .spells-table.active, .voc-badge, .spells-clear, etc. —
   só repaletados, sem mexer no markup gerado dinamicamente. */

@import url('https://fonts.googleapis.com/css2?family=Cardo:ital,wght@0,400;0,700;1,400&family=EB+Garamond:ital,wght@0,500;0,600;1,500;1,600&display=swap');

.spells-page {
    --sp-bg-card:       #0b0f17;
    --sp-bg-soft:       rgba(0, 0, 0, 0.25);
    --sp-border:        rgba(148, 163, 184, 0.18);
    --sp-border-strong: rgba(148, 163, 184, 0.32);
    --sp-accent:        #94a3b8;
    --sp-accent-hi:     #cbd5e1;
    --sp-text:          #e2e8f0;
    --sp-text-soft:     rgba(226, 232, 240, 0.62);
    --sp-text-mute:     rgba(226, 232, 240, 0.42);
    --sp-stat-value:    #f1f5f9;
    --sp-words:         #d4af7a;            /* incantation em tom dourado envelhecido (não neon) */
    --sp-font-display:  'Cardo', 'Trajan Pro', 'Times New Roman', serif;

    color: var(--sp-text);
    font-size: 13px;
    line-height: 1.5;
    width: 100%;
    box-sizing: border-box;
    padding: 0 12px;
}

/* Title agora usa a classe global .page-title (em components.css) — só intro
   continua específica do escopo spells. */
.spells-intro {
    margin: -6px 0 18px;
    color: rgba(226, 232, 240, 0.78);
    font-size: 13px;
    line-height: 1.55;
    max-width: 680px;
}

/* === Tabs — active com sublinha dourada + sem caixa pesada === */
.spells-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--sp-border);
}
.spells-tab-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: none;
    background: transparent;
    color: var(--sp-text-soft);
    font-family: var(--sp-font-display);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
    /* mix case (sem uppercase) — Cinzel maior fica mais legível com caps + lowercase */
    cursor: pointer;
    transition: color 0.15s ease;
    margin-bottom: -1px;       /* sublinha cobre exatamente o border-bottom do tabs */
}
.spells-tab-button::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 0;
    height: 2px;
    background: transparent;
    transition: background 0.15s ease;
}
.spells-tab-button:hover { color: var(--sp-text); }
.spells-tab-button:hover::after { background: var(--sp-border-strong); }
.spells-tab-button.active { color: var(--sp-accent-hi); }
.spells-tab-button.active::after {
    background: var(--sp-accent);
    /* sem box-shadow — paleta slate é discreta, glow ficava chamativo */
}
.spells-tab-button__count {
    display: inline-block;
    padding: 1px 7px;
    background: rgba(148, 163, 184, 0.14);
    border-radius: 9px;
    font-family: system-ui, sans-serif;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--sp-text-soft);
    text-transform: none;
    line-height: 1.3;
}
.spells-tab-button.active .spells-tab-button__count {
    background: rgba(148, 163, 184, 0.22);
    color: var(--sp-accent-hi);
}

/* === Controls — sem caixa em volta, 2 linhas separadas === */
.spells-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 22px;
    padding: 0;
    background: transparent;
    border: none;
}
.spells-controls__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px 22px;
}
.spells-controls__row--roles { padding-top: 4px; }

.spells-control { display: inline-flex; align-items: center; gap: 10px; }
.spells-control label {
    color: var(--sp-text-soft);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 600;
}

/* Inputs estilo material (border-bottom só) — minimalista, não compete com a tabela */
.spells-control select,
.spells-control input[type="text"] {
    padding: 6px 4px;
    border: none;
    border-bottom: 1px solid var(--sp-border-strong);
    border-radius: 0;
    background: transparent;
    color: var(--sp-text);
    font-size: 13px;
    min-width: 180px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.spells-control input[type="text"]::placeholder { color: var(--sp-text-mute); font-style: italic; }
.spells-control select:focus,
.spells-control input[type="text"]:focus {
    outline: none;
    border-bottom-color: var(--sp-accent);
    box-shadow: 0 1px 0 0 var(--sp-accent);
}
.spells-control select {
    /* preserva chevron nativo mas sutil */
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--sp-text-soft) 50%),
                      linear-gradient(135deg, var(--sp-text-soft) 50%, transparent 50%);
    background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 24px;
}

.spells-roles { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.spells-roles .ck { gap: 6px; cursor: pointer; font-size: 12.5px; color: var(--sp-text); text-transform: none; letter-spacing: 0; font-weight: 400; }
.spells-roles input[type="checkbox"] { accent-color: var(--sp-accent); margin: 0; }

/* Botão CLEAR FILTERS — sutil, parece quase um link */
.spells-clear {
    margin-left: auto;       /* empurra pro lado direito da linha */
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    color: var(--sp-text-mute);
    font-size: 11px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.spells-clear:hover {
    color: var(--sp-accent-hi);
    border-color: rgba(148, 163, 184, 0.35);
    background: rgba(148, 163, 184, 0.06);
}

/* === Tabela slate (reusa visual de table-standard sem aplicar a classe) === */
.spells-table { display: none; }
.spells-table.active { display: block; }
.spells-page.searching .spells-table { display: block; }

.spells-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--sp-bg-card);
    border: 1px solid var(--sp-border-strong);
    border-radius: 4px;
    overflow: hidden;
    table-layout: fixed;
    margin-bottom: 18px;
}
.spells-table thead { background: rgba(36, 36, 56, 0.85); }   /* mesmo tom do .section-title-row */
.spells-table th {
    padding: 8px 10px;
    color: var(--sp-text);
    /* sem text-transform: uppercase — labels já vêm no template com casing apropriado
       (Spell, Words, MLvl, Mana, Creates, Vocations) e ocupam menos largura em mixed case. */
    font-size: 11px;
    letter-spacing: 0.2px;
    text-align: left;
    border-bottom: 1px solid var(--sp-border-strong);
    white-space: nowrap;
    font-weight: 600;
}
.spells-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--sp-border);
    font-size: 12.5px;
    vertical-align: middle;
}
.spells-table tbody tr:nth-child(even) { background: rgba(148, 163, 184, 0.04); }
.spells-table tbody tr:hover { background: rgba(148, 163, 184, 0.10); }

/* Sticky header — apenas quando não está em modo busca (search mostra todas tabs) */
.spells-page:not(.searching) .spells-table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(36, 36, 56, 0.95);
    backdrop-filter: blur(2px);
}

/* === Words/Incantation — destaque da página, fonte maior e mais legível.
       Cobre col 2 das tabelas instant e conjure (a rune tem 'Charges' aí — override abaixo).
       EB Garamond italic 600: serif clássica, vibe medieval mas com leitura confortável
       (IM Fell DW Pica tinha visual mais autêntico mas era cansativa em corrida). */
.spells-table td.spell-words,
.spells-table td:nth-child(2) {
    font-family: 'EB Garamond', 'Cardo', 'Times New Roman', serif;
    font-style: italic;
    font-weight: 600;
    font-size: 16px;
    color: var(--sp-words);
    letter-spacing: 0.2px;
}
/* charges (rune-table coluna 2) é número puro — desfaz italics/serif/cor */
#rune-table td:nth-child(2) {
    font-style: normal;
    font-family: inherit;
    font-size: 12.5px;
    color: var(--sp-text);
    letter-spacing: 0;
}

/* === Spell name cell (icon + nome) — nome em fonte menor já que words é o destaque === */
.spell-name { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 10px; }
.spell-name a {
    color: var(--sp-accent-hi);
    text-decoration: none;
    font-size: 12px;
    letter-spacing: 0.2px;
}
.spell-name a:hover { color: var(--sp-text); text-decoration: underline; }

/* === Icon wrapper (slate, igual .task-sprite/.monster-sprite) === */
.icon-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    box-sizing: border-box;
    border: 1px solid var(--sp-border);
    background: var(--sp-bg-soft);
    border-radius: 4px;
    overflow: hidden;
    line-height: 0;
}
.icon-wrapper.icon-placeholder { color: var(--sp-text-mute); font-size: 11px; }
.icon-wrapper.missing-icon {
    border-style: dashed;
    color: var(--sp-text-mute);
    font-size: 9px;
    line-height: 1.2;
    text-align: center;
    padding: 2px;
}
.icon-wrapper .item-icon { display: block; }
.item-icon { width: 32px; height: 32px; display: block; image-rendering: pixelated; }
.item-icon.instant-icon,
.item-icon.conjure-icon,
.item-icon.rune-icon { width: 32px; height: 32px; }

.icon-wrapper.tile { display: flex; align-items: center; justify-content: center; gap: 1px; padding: 0; }
.icon-wrapper.tile .item-icon {
    height: 32px;
    width: calc(32px / var(--tile-repeat, 1));
    flex: 0 0 auto;
    display: block;
    image-rendering: pixelated;
}

.icon-wrapper.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    place-items: center;
    padding: 0;
}
.icon-wrapper.grid .item-icon { width: 10px; height: 10px; image-rendering: pixelated; display: block; }

/* === Vocation badges (slate base + accent dessaturado por vocação) === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    margin: 1px 4px 1px 0;
    border-radius: 3px;
    border: 1px solid var(--sp-border-strong);
    background: rgba(18, 22, 30, 0.45);
    color: var(--sp-text-soft);
    font-size: 11px;
    letter-spacing: 0.3px;
    line-height: 1.4;
}
.voc-badge { cursor: pointer; user-select: none; transition: background 0.12s, color 0.12s, border-color 0.12s; }
.voc-badge:hover { color: var(--sp-text); border-color: var(--sp-accent); }
.voc-badge:focus { outline: 1px dashed var(--sp-accent); outline-offset: 2px; }
/* Tint sutil por vocação — attribute selector pra não exigir mudança no JS.
   Cobre promotions também (Master Sorcerer, Elder Druid, Royal Paladin, Elite Knight). */
.voc-badge[data-vocation*="Sorcerer" i] { color: #b377ff; border-color: rgba(179, 119, 255, 0.4); }
.voc-badge[data-vocation*="Druid" i]    { color: #7bc950; border-color: rgba(123, 201, 80, 0.4); }
.voc-badge[data-vocation*="Paladin" i]  { color: #ffe066; border-color: rgba(255, 224, 102, 0.4); }
.voc-badge[data-vocation*="Knight" i]   { color: #d4d4d4; border-color: rgba(212, 212, 212, 0.4); }

/* === "Old" chip dentro do icon-wrapper === */
.icon-wrapper .old-chip {
    position: absolute;
    top: 2px;
    left: 2px;
    z-index: 0;
    display: inline-block;
    padding: 1px 6px;
    background: rgba(154, 36, 36, 0.78);
    border: 1px solid rgba(154, 36, 36, 0.95);
    border-radius: 3px;
    font: 700 9.5px/1 var(--sp-font-display);
    letter-spacing: 0.5px;
    color: #ffe7e7;
    text-transform: uppercase;
}
.icon-wrapper .old-chip::before,
.icon-wrapper .old-chip::after { content: none !important; }
.icon-wrapper.has-old .item-icon { position: relative; z-index: 1; transform: translateY(2px); }

/* === Empty / placeholder rows === */
.empty-row td { text-align: center; color: var(--sp-text-mute); padding: 20px 12px; font-style: italic; }

/* === Sort caret === */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--sp-accent-hi); }
.sortable .sort-caret {
    margin-left: 1px;
    opacity: 0.65;
    font-size: 0.7em;
    vertical-align: middle;
}
.sorted-asc .sort-caret::after  { content: '▲'; }
.sorted-desc .sort-caret::after { content: '▼'; }

/* === "Creates" popover (slate em vez do azul anterior) === */
.stacked-icons { display: inline-flex; align-items: center; gap: 6px; }
.arrow-right { line-height: 1; font-size: 16px; opacity: 0.6; user-select: none; margin: 0 4px; color: var(--sp-text-soft); }
.count-badge {
    position: absolute;
    right: 2px;
    bottom: 2px;
    z-index: 2;
    background: rgba(0, 0, 0, 0.78);
    border: 1px solid var(--sp-border-strong);
    color: var(--sp-text);
    font-size: 10px;
    line-height: 1;
    padding: 1px 4px;
    border-radius: 3px;
    pointer-events: none;
}
.creates-preview-wrapper { position: relative; display: inline-block; }
/* Popover sai pra ESQUERDA (a coluna Creates fica perto da borda direita;
   se sair pra direita, fica atrás da sidebar do site). */
.creates-popover {
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--sp-bg-card);
    border: 1px solid var(--sp-border-strong);
    border-radius: 6px;
    padding: 8px;
    z-index: 30;
    display: none;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
    white-space: nowrap;
}
.creates-preview-wrapper:hover .creates-popover { display: block; }
.creates-popover::before {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 0 6px 6px;
    border-style: solid;
    border-color: transparent transparent transparent var(--sp-border-strong);
}

/* === Column widths (mantidos do CSS antigo) === */
#instant-table, #conjure-table, #rune-table { table-layout: fixed; word-wrap: break-word; }

#instant-table th:nth-child(1), #instant-table td:nth-child(1) { width: 28%; }
#instant-table th:nth-child(2), #instant-table td:nth-child(2) { width: 22%; }
#instant-table th:nth-child(3), #instant-table td:nth-child(3) { width: 12%; }
#instant-table th:nth-child(4), #instant-table td:nth-child(4) { width: 12%; }
#instant-table th:nth-child(5), #instant-table td:nth-child(5) { width: 26%; }

#conjure-table th:nth-child(1), #conjure-table td:nth-child(1) { width: 28%; }
#conjure-table th:nth-child(2), #conjure-table td:nth-child(2) { width: 22%; }
#conjure-table th:nth-child(3), #conjure-table td:nth-child(3) { width: 9%; }
#conjure-table th:nth-child(4), #conjure-table td:nth-child(4) { width: 9%; }
#conjure-table th:nth-child(5), #conjure-table td:nth-child(5) { width: 12%; }
#conjure-table th:nth-child(6), #conjure-table td:nth-child(6) { width: 20%; }

#rune-table th:nth-child(1), #rune-table td:nth-child(1) { width: 36%; }
#rune-table th:nth-child(2), #rune-table td:nth-child(2) { width: 12%; }
#rune-table th:nth-child(3), #rune-table td:nth-child(3) { width: 12%; }
#rune-table th:nth-child(4), #rune-table td:nth-child(4) { width: 12%; }
#rune-table th:nth-child(5), #rune-table td:nth-child(5) { width: 28%; }

/* === Mobile — card layout (table vira lista de cards verticais) ===
   <tr> vira flex container; <td> são flex items posicionados.
   Labels curtos (ML/MN) pra não quebrar em telas estreitas; vocations
   e creates ocupam linha inteira. Popover desabilitado (toque fica
   confuso) — sprite + xN no badge já mostra o essencial. */
@media (max-width: 720px) {
    .spells-control { flex: 1 1 100%; }
    .spells-control select, .spells-control input[type="text"] { width: 100%; min-width: 0; }
    .spells-page { padding: 0 6px; }

    .spells-table table {
        display: block;
        background: transparent;
        border: none;
        margin-bottom: 12px;
    }
    .spells-table thead { display: none; }
    .spells-table tbody { display: block; }

    .spells-table tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        /* gap omitido: tr table-row em browsers reais ignora gap mesmo com display:flex.
           Em vez disso, espaçamento é feito via margin direta nos <td> abaixo. */
        padding: 10px 12px;
        margin-bottom: 8px;
        border: 1px solid var(--sp-border);
        border-radius: 4px;
        background: var(--sp-bg-card);
    }
    .spells-table tbody tr:nth-child(even) { background: rgba(148, 163, 184, 0.04); }
    .spells-table tbody tr:hover { background: rgba(148, 163, 184, 0.07); }

    .spells-table td {
        display: block;       /* sem isso o td herda table-cell e quebra layout flex */
        padding: 0;
        border: none;
        font-size: 12px;
        flex: 0 0 auto;
        margin: 3px 14px 3px 0;   /* substitui o gap do flex container */
    }
    /* As regras `#<table-id> td:nth-child(N) { width: X% }` no escopo desktop
       vencem por especificidade (ID > classe). Aqui zera width via !important
       pra cada uma das 3 tabelas — sem isso o td fica com 12% do parent e
       o texto vaza por cima do td vizinho. */
    #instant-table th, #instant-table td,
    #conjure-table th, #conjure-table td,
    #rune-table th,    #rune-table td { width: auto !important; }
    .spells-table td:last-child { margin-right: 0; }

    /* === Col 1: nome — linha inteira (header do card) === */
    .spells-table td:nth-child(1) {
        flex: 1 1 100%;
        padding-bottom: 6px;
        border-bottom: 1px solid var(--sp-border);
    }
    .spell-name { display: flex; align-items: center; gap: 10px; }
    .spell-name a {
        font-size: 14px;
        font-family: var(--sp-font-display);
        letter-spacing: 0.4px;
    }
    .icon-wrapper { width: 36px; height: 36px; flex-shrink: 0; }
    .item-icon { width: 28px; height: 28px; }
    /* Conjure/Rune não têm .spell-name wrapper — formatar texto puro como título */
    #conjure-table td:nth-child(1),
    #rune-table td:nth-child(1) {
        font-size: 14px;
        font-family: var(--sp-font-display);
        color: var(--sp-accent-hi);
        letter-spacing: 0.4px;
        text-transform: capitalize;
    }

    /* === Col 2 (words em instant/conjure): destaque dourado em linha cheia === */
    .spells-table td.spell-words,
    .spells-table td:nth-child(2) {
        flex: 1 1 100%;
        font-size: 14.5px;
    }
    /* Rune col 2 = Charges (numérico), label inline e compacto, não fica em linha cheia */
    #rune-table td:nth-child(2) {
        flex: 0 0 auto;
        font-size: 12px;
        white-space: nowrap;
    }
    #rune-table td:nth-child(2)::before {
        content: "Charges ";
        color: var(--sp-text-mute);
        font-style: normal;
        margin-right: 2px;
    }

    /* === Mag.Lvl + Mana: chips inline compactos === */
    .spells-table td:nth-child(3),
    .spells-table td:nth-child(4) {
        font-size: 12.5px;
        white-space: nowrap;
    }
    .spells-table td:nth-child(3)::before {
        content: "Mag. Lvl ";
        color: var(--sp-text-mute);
        margin-right: 2px;
    }
    .spells-table td:nth-child(4)::before {
        content: "Mana ";
        color: var(--sp-text-mute);
        margin-right: 2px;
    }

    /* === Creates (conjure col 5): linha cheia, label discreto + sprite === */
    #conjure-table td:nth-child(5) {
        flex: 1 1 100%;
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 2px;
        padding-top: 6px;
        border-top: 1px solid var(--sp-border);
    }
    #conjure-table td:nth-child(5)::before {
        content: "Creates";
        color: var(--sp-text-mute);
        font-size: 10.5px;
        text-transform: uppercase;
        letter-spacing: 0.8px;
    }
    /* No mobile o popover só atrapalha (não tem hover); deixa o badge xN visível e basta */
    .creates-popover { display: none !important; }

    /* === Vocations (último td) — linha cheia com badges flex-wrap === */
    #instant-table td:nth-child(5),
    #conjure-table td:nth-child(6),
    #rune-table    td:nth-child(5) {
        flex: 1 1 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 6px;
        margin-top: 2px;
        padding-top: 6px;
        border-top: 1px solid var(--sp-border);
    }
    #instant-table td:nth-child(5)::before,
    #conjure-table td:nth-child(6)::before,
    #rune-table    td:nth-child(5)::before {
        content: "Vocations";
        color: var(--sp-text-mute);
        font-size: 10.5px;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        white-space: nowrap;
        margin-right: 4px;
    }
    .badge { margin: 0; }

    /* Empty row mantém centralizado */
    .spells-table tr.empty-row { display: block; text-align: center; }
    .spells-table tr.empty-row td { display: block; padding: 16px 8px; }
    .spells-table tr.empty-row td::before { content: none; }
}
