/* ═══════════════════════════════════════════════════
   Campi da Padel Finance — Dual Theme UI
   ═══════════════════════════════════════════════════ */

/* ── DARK THEME (default) ── */
[data-theme="dark"] {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-card-hover: #1c1c1c;
    --bg-sidebar: #0d0d0d;
    --bg-input: #1a1a1a;
    --bg-modal: #1f1f1f;
    --surface: rgba(255,255,255,0.05);
    --card: rgba(255,255,255,0.038);
    --border: #252525;
    --border-hover: #3a3a3a;
    --text: #e8e8e8;
    --text-secondary: #aaa;
    --text-muted: #777;
    --text-dim: #555;
    --shadow: rgba(0,0,0,0.4);
}

/* ── LIGHT THEME ── */
[data-theme="light"] {
    --bg: #f4f5f7;
    --bg-card: #ffffff;
    --bg-card-hover: #fafafa;
    --bg-sidebar: #ffffff;
    --bg-input: #f0f1f3;
    --bg-modal: #ffffff;
    --surface: rgba(0,0,0,0.04);
    --card: rgba(0,0,0,0.022);
    --border: #e0e0e0;
    --border-hover: #ccc;
    --text: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #888;
    --text-dim: #aaa;
    --shadow: rgba(0,0,0,0.08);
}

/* ── SHARED COLORS ── */
:root {
    --gold: #c9a84c;
    --gold-dim: rgba(201,168,76,0.15);
    --green: #22c55e;
    --green-dim: rgba(34,197,94,0.12);
    --red: #ef4444;
    --red-dim: rgba(239,68,68,0.12);
    --blue: #3b82f6;
    --blue-dim: rgba(59,130,246,0.12);
    --orange: #f59e0b;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-w: 230px;
    --chat-w: 380px;
    --topbar-h: 52px;
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; transition: background var(--transition), color var(--transition); }

/* ── LAYOUT ── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
#sidebar {
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--bg-sidebar); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; transition: transform 0.3s, background var(--transition);
    z-index: 200;
}
.sidebar-header {
    padding: 16px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo { max-width: 160px; height: auto; object-fit: contain; }
.sidebar-nav { flex: 1; padding: 8px; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); text-decoration: none; font-size: 13px; font-weight: 500;
    transition: all var(--transition); margin-bottom: 1px; white-space: nowrap;
}
.nav-item:hover { background: var(--bg-card); color: var(--text); }
.nav-item.active { background: var(--gold-dim); color: var(--gold); font-weight: 600; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); }
.entity-switch { display: flex; gap: 4px; }
.entity-btn {
    flex: 1; padding: 6px 4px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-muted); font-size: 11px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
}
.entity-btn:hover { border-color: var(--border-hover); }
.entity-btn.active { background: var(--gold-dim); color: var(--gold); border-color: var(--gold); }

/* ── TOPBAR ── */
#content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#topbar {
    height: var(--topbar-h); min-height: var(--topbar-h);
    padding: 0 16px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border); background: var(--bg);
    transition: background var(--transition);
}
#page-title { flex: 1; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-select {
    padding: 4px 6px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text); font-size: 11px; font-weight: 600;
    cursor: pointer;
}
.icon-btn {
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-muted); cursor: pointer; font-size: 18px; transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-card); border-color: var(--border); color: var(--text); }
.theme-icon { width: 18px; height: 18px; }

/* ── USER MENU ── */
.user-menu { position: relative; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--gold-dim);
    border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--gold); transition: all var(--transition);
}
.user-avatar:hover { border-color: var(--gold); }
.dropdown {
    display: none; position: absolute; right: 0; top: 42px; width: 240px;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 8px 24px var(--shadow); z-index: 500; overflow: hidden;
}
.dropdown.show { display: block; }
.dropdown-header { padding: 12px 14px 2px; font-weight: 600; font-size: 13px; }
.dropdown-email { padding: 2px 14px 10px; font-size: 11px; color: var(--text-muted); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-item {
    display: block; padding: 8px 14px; font-size: 13px; color: var(--text); text-decoration: none;
    transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-input); }
.dropdown-danger { color: var(--red); }

/* ── VIEW CONTAINER ── */
#view-container { flex: 1; overflow-y: auto; padding: 20px; }

/* ── BUTTONS ── */
.btn {
    padding: 7px 14px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600;
    border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
    cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.btn:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-gold { border-color: var(--gold); color: var(--gold); }
.btn-gold:hover { background: var(--gold-dim); }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); }
.btn-red { border-color: var(--red); color: var(--red); }
.btn-primary { background: var(--gold); color: #000; border-color: var(--gold); font-weight: 700; }
.btn-primary:hover { opacity: 0.9; }

/* ── CARDS ── */
.card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; transition: all var(--transition);
}
.card:hover { border-color: var(--border-hover); }
.card-title { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 700; font-family: var(--mono); line-height: 1.2; }
.card-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.card-positive { color: var(--green); }
.card-negative { color: var(--red); }
.card-gold { color: var(--gold); }

/* ── KPI GRID ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* ── TABLE ── */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    padding: 8px 10px; text-align: left; font-size: 10px; font-weight: 700;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
[data-theme="dark"] tbody td { border-color: #1a1a1a; }
tbody tr:hover { background: var(--bg-card-hover); }
.amount { font-family: var(--mono); text-align: right; font-size: 12px; }
.amount-positive { color: var(--green); }
.amount-negative { color: var(--red); }

/* ── BADGES ── */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.4px;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-gold { background: var(--gold-dim); color: var(--gold); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }

/* ── SEARCH & FILTERS ── */
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-input, .filter-select {
    padding: 7px 12px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px;
    transition: border-color var(--transition);
}
.search-input { flex: 1; min-width: 160px; }
.search-input:focus, .filter-select:focus { outline: none; border-color: var(--gold); }
.search-input::placeholder { color: var(--text-dim); }

/* ── SECTION ── */
.section { margin-bottom: 20px; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* ── FORMS (CRUD) ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px; font-family: var(--font);
    transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--gold); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ── MODAL ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 900; }
.modal-overlay.show { display: block; }
.modal-container {
    display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
    width: 90%; max-width: 560px; max-height: 85vh; overflow-y: auto;
    background-color: var(--bg-modal) !important; /* IMPORTANT: kills any transparency */
    border: 1px solid var(--border-hover); border-radius: var(--radius);
    box-shadow: 0 24px 80px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
    z-index: 1000; padding: 24px;
    backdrop-filter: none;
    opacity: 1 !important;
}
/* Per-theme HARD overrides — bullet-proof against any transparent inheritance */
[data-theme="dark"] .modal-container { background-color: #1f1f1f !important; }
[data-theme="light"] .modal-container { background-color: #ffffff !important; box-shadow: 0 24px 80px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06); }
.modal-container.show { display: block; }
.modal-container.modal-large {
    width: 78%; max-width: 1280px; max-height: 90vh; padding: 28px;
    background-color: var(--bg-modal) !important;
}
@media (max-width: 900px) { .modal-container.modal-large { width: 95%; padding: 16px; } }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }

/* ── CHAT PANEL ── */
#chat-panel {
    width: var(--chat-w); min-width: var(--chat-w); background: var(--bg-sidebar);
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
    transition: all 0.3s; overflow: hidden;
}
#chat-panel.chat-hidden { width: 0; min-width: 0; border: none; }
.chat-header {
    padding: 12px 14px; display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid var(--border); min-height: 48px;
}
.chat-header h3 { flex: 1; font-size: 13px; color: var(--gold); white-space: nowrap; }
.chat-model-select select {
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
    font-size: 10px; padding: 3px 5px; border-radius: 4px;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; }
.chat-welcome { text-align: center; color: var(--text-muted); font-size: 13px; padding: 30px 10px; }
.chat-welcome p { margin-bottom: 6px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.chat-suggestions button {
    padding: 5px 10px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 14px; color: var(--text-muted); font-size: 11px; cursor: pointer; transition: all var(--transition);
}
.chat-suggestions button:hover { border-color: var(--gold); color: var(--gold); }

.chat-msg { margin-bottom: 14px; }
.chat-msg-user { text-align: right; }
.chat-msg-user .chat-bubble { background: var(--gold-dim); color: var(--text); border-radius: 12px 12px 4px 12px; display: inline-block; padding: 8px 12px; max-width: 85%; text-align: left; font-size: 13px; line-height: 1.5; }
.chat-msg-assistant .chat-bubble { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px 12px 12px 4px; display: inline-block; padding: 10px 12px; max-width: 90%; font-size: 13px; line-height: 1.5; }
.chat-actions { margin-top: 8px; display: flex; gap: 6px; }
.chat-action-btn { padding: 5px 12px; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer; border: none; }
.chat-action-approve { background: var(--green); color: #fff; }
.chat-action-reject { background: var(--bg-card); color: var(--red); border: 1px solid var(--red); }
.chat-action-preview { background: var(--bg-input); border: 1px solid var(--border); padding: 8px 10px; border-radius: 6px; margin-top: 6px; font-size: 11px; font-family: var(--mono); white-space: pre-wrap; color: var(--text-secondary); max-height: 200px; overflow-y: auto; }

.chat-input-area { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 6px; align-items: flex-end; }
#chat-input {
    flex: 1; padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px; font-family: var(--font);
    resize: none; max-height: 100px;
}
#chat-input:focus { outline: none; border-color: var(--gold); }
#chat-send {
    width: 36px; height: 36px; background: var(--gold); border: none; border-radius: var(--radius-sm);
    color: #000; cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
#chat-send:hover { opacity: 0.9; }

/* ── LOADING ── */
.loading { display: flex; align-items: center; justify-content: center; padding: 30px; color: var(--text-muted); font-size: 13px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESPONSIVE ── */
@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
@media (max-width: 768px) {
    #sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); z-index: 300; box-shadow: 4px 0 20px var(--shadow); }
    #sidebar.open { transform: translateX(0); }
    #menu-toggle { display: flex !important; }
    #chat-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 300; box-shadow: -4px 0 20px var(--shadow); }
    #chat-panel.chat-hidden { transform: translateX(100%); }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    #view-container { padding: 14px; }
    .form-row { grid-template-columns: 1fr; }
    .modal-container { width: 95%; max-width: none; padding: 16px; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    #chat-panel { width: 100%; min-width: 100%; }
    .topbar-actions .btn:not(.btn-gold) { display: none; }
    #page-title { font-size: 14px; }
    .card-value { font-size: 22px; }
}
@media (min-width: 1400px) {
    .kpi-grid { grid-template-columns: repeat(6, 1fr); }
    #view-container { padding: 28px; }
}

/* Toggle del sidebar visible en desktop + estado colapsado (tira de íconos) */
@media (min-width: 769px) {
    #menu-toggle { display: flex; }
    #app.sidebar-collapsed #sidebar { width: 60px; min-width: 60px; }
    #app.sidebar-collapsed .nav-item > span { display: none; }        /* texto + badges */
    #app.sidebar-collapsed .nav-item { justify-content: center; padding: 10px 0; }
    #app.sidebar-collapsed .nav-icon { margin: 0; }
    #app.sidebar-collapsed .sidebar-logo { display: none; }
    #app.sidebar-collapsed .sidebar-header { justify-content: center; padding: 14px 4px; }
    #app.sidebar-collapsed .entity-switch, #app.sidebar-collapsed .sidebar-footer > * { display: none; }
}

/* Close dropdown on click outside */
body:not(:has(.dropdown.show)) .modal-overlay { pointer-events: none; }

/* ─── Super-admin-only UI hooks ─── */
.super-admin-only { display: none !important; }
body[data-super-admin="true"] .super-admin-only { display: block !important; }
body[data-super-admin="true"] .super-admin-only.dropdown-item { display: block !important; }

/* ─── Permission matrix table ─── */
.perm-matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-matrix th, .perm-matrix td {
    padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: center;
}
.perm-matrix th { background: var(--surface); color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.perm-matrix td.module-cell { text-align: left; font-weight: 600; }
.perm-matrix .entity-madrid { color: #1a5da6; }
.perm-matrix .entity-kira   { color: #D4A843; }
.perm-matrix input[type=checkbox] { cursor: pointer; }

/* ─── Company tabs (Madrid / Kira / Vista Combinata) ─── */
.company-tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    overflow-x: auto;
}
.company-tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 12px 22px;
    cursor: pointer;
    color: var(--text-muted);
    text-align: left;
    transition: all var(--transition);
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: inherit;
}
.company-tab:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.company-tab.active { color: var(--text); background: var(--bg); }
.company-tab .company-tab-label { font-weight: 700; font-size: 14px; }
.company-tab .company-tab-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.3px; }

/* Brand colour per entity — only the active tab carries it */
.company-tab[data-entity="all"].active     { border-bottom-color: var(--gold); }
.company-tab[data-entity="campida"].active { border-bottom-color: #134178; }
.company-tab[data-entity="kira"].active    { border-bottom-color: #D4A843; }

/* Top-of-page accent stripe when a single entity is active. body carries
   data-entity so other views can style themselves contextually. */
body[data-entity="campida"] .company-tab[data-entity="campida"] .company-tab-label { color: #1a5da6; }
body[data-entity="kira"]    .company-tab[data-entity="kira"]    .company-tab-label { color: #D4A843; }

/* Mobile: stack tabs */
@media (max-width: 768px) {
    .company-tabs { flex-direction: column; padding: 0; }
    .company-tab { min-width: unset; padding: 10px 16px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; }
    .company-tab.active { border-bottom-color: var(--border); border-left-width: 3px; }
    .company-tab[data-entity="all"].active     { border-left-color: var(--gold); }
    .company-tab[data-entity="campida"].active { border-left-color: #134178; }
    .company-tab[data-entity="kira"].active    { border-left-color: #D4A843; }
}



/* ================================================================
   ENTITY DROPDOWN — compact context switcher in topbar
   Sits next to theme toggle. Replaces the bulky cards row.
   ================================================================ */
.entity-dropdown { position: relative; display: inline-flex; }
.entity-dd-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-modal);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 12px 7px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s ease;
    min-width: 170px;
    height: 36px;
    line-height: 1;
}
.entity-dd-trigger:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}
.entity-dd-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gold);
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(212,168,67,0.18);
}
.entity-dd-dot[data-current="campida"] {
    background: #1a5da6;
    box-shadow: 0 0 0 3px rgba(26,93,166,0.18);
}
.entity-dd-dot[data-current="kira"] {
    background: #D4A843;
    box-shadow: 0 0 0 3px rgba(212,168,67,0.22);
}
.entity-dd-label {
    flex: 1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.entity-dd-chevron {
    opacity: 0.6;
    transition: transform 0.15s;
}
.entity-dropdown.open .entity-dd-chevron { transform: rotate(180deg); }
.entity-dd-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-modal);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    min-width: 280px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.22);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: dd-fade-in 0.16s ease-out;
}
@keyframes dd-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.entity-dd-menu[hidden] { display: none; }
.entity-dd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text);
    text-align: left;
    font-family: inherit;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.entity-dd-item:hover {
    background: var(--bg-card-hover);
    transform: translateX(2px);
    border-color: var(--border-hover);
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}
.entity-dd-item[data-entity="campida"]:hover { border-color: #1a5da6; box-shadow: 0 2px 12px rgba(26,93,166,0.20); }
.entity-dd-item[data-entity="kira"]:hover    { border-color: #D4A843; box-shadow: 0 2px 12px rgba(212,168,67,0.20); }
.entity-dd-item-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gold);
    flex-shrink: 0;
}
.entity-dd-item-dot[data-entity="campida"] { background: #1a5da6; }
.entity-dd-item-dot[data-entity="kira"] { background: #D4A843; }
.entity-dd-item-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.entity-dd-item-name { font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.entity-dd-item-sub { font-size: 11px; color: var(--text-muted); line-height: 1.2; }
.entity-dd-item.active {
    background: var(--bg-card-hover);
    border-color: var(--gold);
}
.entity-dd-item.active[data-entity="campida"] { border-color: #1a5da6; background: rgba(26,93,166,0.08); }
.entity-dd-item.active[data-entity="kira"]    { border-color: #D4A843; background: rgba(212,168,67,0.10); }
.entity-dd-item.active::after {
    content: "¹3";
    margin-left: auto;
    color: var(--gold);
    font-weight: 700;
    font-size: 16px;
}
.entity-dd-item.active[data-entity="campida"]::after { color: #1a5da6; }
.entity-dd-item.active[data-entity="kira"]::after { color: #D4A843; }

body[data-entity="campida"] .entity-dd-trigger { border-color: #1a5da6; }
body[data-entity="kira"] .entity-dd-trigger { border-color: #D4A843; }

/* Brand-tint the dropdown trigger label per active entity */
body[data-entity="campida"] .entity-dd-trigger { border-color: #1a5da6; }
body[data-entity="kira"] .entity-dd-trigger { border-color: #D4A843; }

/* KPIs compactos (Kira Reservas/Canchas) */
.kpi-grid.compact { gap: 8px; margin-bottom: 14px; }
.kpi-grid.compact .card { padding: 9px 11px; }
.kpi-grid.compact .card-title { font-size: 9px; letter-spacing: .5px; margin-bottom: 2px; }
.kpi-grid.compact .card-value { font-size: 18px; }

/* ── Topbar responsive: evita che i controlli si sovrappongano su schermi
   stretti (es. finestra divisa a meta'). I bottoni flex:none non si
   restringono, quindi su misure piccole si nasconde il testo non essenziale. */
@media (max-width: 1200px) {
  #gsearch-hint { display: none; }
  #gsearch-wrap { gap: 12px !important; padding: 0 6px !important; }
}
@media (max-width: 1000px) {
  #ai-btn-text { display: none; }               /* bottone AI -> solo ✨ */
  #gsearch-wrap { gap: 8px !important; }
  #gsearch-wrap > div:first-child { flex: 0 1 260px !important; }
  #page-title { max-width: 16vw !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 820px) {
  #entity-dd-label { display: none; }            /* entita' -> solo pallino + freccia */
  #gsearch-wrap > div:first-child { display: none; }  /* nascondi la ricerca, tieni il bottone AI */
  #page-title { max-width: 34vw !important; }
  #topbar { gap: 8px !important; }
}

/* ═══════════════════════ MOBILE (pedido Ludwing 01/09) ═══════════════════════
   La app se usa dal telefono: CRM di entrambe le aziende, Chiusura e i suoi
   modali, chat AI e Decisioni. Regole GLOBALI: i modali diventano a schermo
   intero, le tabelle scorrono in orizzontale invece di rompere il layout, i
   form si impilano, i bottoni hanno misura da dito e gli input a 16px evitano
   lo zoom automatico di iOS. */
@media (max-width: 900px) {
  .modal-container.modal-large { width: 96%; max-width: 96%; }
}
@media (max-width: 640px) {
  /* modali a schermo intero (CRM scheda, Chiusura, AI, Decisioni, borsellino…) */
  .modal-container, .modal-container.modal-large {
    width: 100vw !important; max-width: none !important;
    height: 100vh; height: 100dvh;
    max-height: 100vh !important; max-height: 100dvh !important;
    top: 0 !important; left: 0 !important; transform: none !important;
    border-radius: 0; border-left: none; border-right: none;
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  /* titolo sempre visibile con la X a portata di pollice */
  .modal-container .modal-title {
    position: sticky; top: -12px; z-index: 6;
    background: var(--bg-modal); padding: 12px 0 8px; margin: -12px 0 10px;
  }
  .modal-close { font-size: 28px; padding: 0 6px; }
  /* bottoni Salva/Annulla sempre raggiungibili in fondo */
  .modal-container .form-actions {
    position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom, 0px));
    z-index: 6; background: var(--bg-modal);
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
    margin-bottom: calc(-16px - env(safe-area-inset-bottom, 0px));
    flex-wrap: wrap; gap: 8px;
  }
  /* input a 16px: sotto, iOS zooma la pagina ad ogni focus */
  .modal-container input, .modal-container select, .modal-container textarea,
  #view-container input, #view-container select, #view-container textarea {
    font-size: 16px !important;
  }
  /* i form si impilano (le .form-row affiancate non entrano) */
  .form-row { flex-wrap: wrap !important; }
  .form-row .form-group { flex: 1 1 100% !important; min-width: 0 !important; }
  /* tabelle: scroll orizzontale col dito, mai layout rotto */
  .modal-container table, .card table, #view-container table {
    display: block; overflow-x: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  /* misure da dito */
  .btn { min-height: 40px; }
  .btn.btn-sm { min-height: 34px; }
  /* niente scroll laterale della pagina */
  #view-container { padding: 12px 10px; overflow-x: hidden; }
  /* le file di chips/bottoni scritte inline (chiusura, CRM, report) si
     AVVOLGONO — tranne i binari con scroll orizzontale voluto (kanban,
     caroselli), riconoscibili dall'overflow-x inline */
  #view-container div[style*="display:flex"]:not([style*="overflow-x"]),
  .modal-container div[style*="display:flex"]:not([style*="overflow-x"]):not([style*="nowrap"]) {
    flex-wrap: wrap !important;
  }
  .view-header { flex-wrap: wrap; gap: 8px; }
  .view-header h2 { font-size: 18px; }
  .card { padding: 12px; }
  .form-actions { flex-wrap: wrap; gap: 8px; }

  /* ── topbar: respiro, non tutto ammassato (feedback Ludwing 01/09) ──
     Restano: menu · titolo · ✨AI · chat · campanella · entita' · avatar.
     Tema e lingua si nascondono (si cambiano dal desktop): 9 controlli in
     una riga da 380px si schiacciavano uno sopra l'altro. */
  #topbar { padding: 0 8px; gap: 6px !important; }
  #page-title { max-width: 24vw !important; font-size: 14px; }
  #gsearch-wrap { flex: 0 0 auto !important; padding: 0 !important; justify-content: flex-end; }
  #gsearch-wrap button { height: 36px !important; padding: 0 10px !important; }
  .topbar-actions { gap: 5px; }
  .topbar-actions #chat-btn { margin-right: 0 !important; }
  #chat-btn, #notif-bell { width: 34px !important; height: 34px !important; }
  #theme-toggle, #lang-select { display: none !important; }
  .entity-dd-trigger { padding: 6px 8px; }
  .icon-btn { width: 34px; height: 34px; }
  .user-avatar { width: 32px; height: 32px; }
}
@media (max-width: 410px) {
  /* schermi piccolissimi: il titolo della pagina vive gia' nel menu */
  #page-title { display: none !important; }
  #topbar { gap: 4px !important; }
}
