:root {
    --primary: #1f6feb;
    --accent: #3fb950;
    --bg: #0d1117;
    --panel: #161b22;
    --border: #232b36;
    --text: #e6edf3;
    --muted: #8b949e;
    --danger: #f85149;
    --hover: rgba(255,255,255,.04);
    --hover-soft: rgba(255,255,255,.02);
    --input-bg: var(--bg);
    --shadow: 0 4px 16px rgba(0,0,0,.35);
    --radius: 12px;
    --font-sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* ── Modo claro (mayor especificidad que el :root del branding) ── */
html[data-theme="light"] {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --border: #e2e6ed;
    --text: #1b2430;
    --muted: #5a6573;
    --hover: rgba(0,0,0,.04);
    --hover-soft: rgba(0,0,0,.025);
    --input-bg: #f9fafc;
    --shadow: 0 4px 16px rgba(20,40,80,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { transition: background-color .2s ease, color .2s ease; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Layout app ── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.sidebar .brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem .8rem;
    border-radius: 8px;
    color: var(--muted);
    font-size: .92rem;
    font-weight: 500;
}
.sidebar nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar-config { border-top: 1px solid var(--border); padding-top: .75rem; margin-bottom: .75rem; }
.sidebar-config-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: .25rem .8rem .4rem; font-weight: 700; }
.sidebar-config a { display: flex; align-items: center; gap: .65rem; padding: .55rem .8rem; border-radius: 8px; color: var(--muted); font-size: .9rem; font-weight: 500; }
.sidebar-config a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.sidebar-config a.active { background: var(--primary); color: #fff; }
.sidebar .user-box { border-top: 1px solid var(--border); padding-top: 1rem; font-size: .85rem; color: var(--muted); }

/* ── Tabs (drill-down tenant) ── */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; flex-wrap: wrap; }
.tabs button { background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--muted); padding: .7rem 1rem; cursor: pointer; font-size: .9rem; font-weight: 600; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem; }
.perm-check { display: flex; align-items: center; gap: .5rem; padding: .5rem .7rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; cursor: pointer; }
.perm-check input { width: auto; }

/* ── Banner "ver como tenant" ── */
.impersonate-banner { display: flex; align-items: center; justify-content: center; gap: 1rem; background: #b45309; color: #fff; padding: .55rem 1rem; font-size: .88rem; font-weight: 600; }
.impersonate-banner button { background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.4); color: #fff; padding: .3rem .8rem; border-radius: 6px; cursor: pointer; font-size: .82rem; font-weight: 600; }
.impersonate-banner button:hover { background: rgba(255,255,255,.3); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 64px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background: var(--panel);
}
.topbar h1 { font-size: 1.15rem; font-weight: 600; }
.content { padding: 2rem; flex: 1; }

/* ── Componentes ── */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.grid { display: grid; gap: 1rem; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 600px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr;} .sidebar{display:none;} }

.stat { text-align: left; }
.stat .value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat .label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem 1.1rem;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    transition: opacity .15s;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: .35rem .7rem; font-size: .8rem; }

.input, select, textarea {
    width: 100%;
    padding: .6rem .8rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: .9rem;
    font-family: inherit;
}
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .35rem; }
.field { margin-bottom: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: .72rem; letter-spacing: .5px; }
tr:hover td { background: var(--hover-soft); }

.badge { display: inline-block; padding: .2rem .6rem; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.badge.green { background: rgba(63,185,80,.15); color: var(--accent); }
.badge.blue { background: rgba(31,111,235,.15); color: var(--primary); }
.badge.gray { background: rgba(139,148,158,.15); color: var(--muted); }
.badge.red { background: rgba(248,81,73,.15); color: var(--danger); }

.lock { color: var(--accent); cursor: help; }
.muted { color: var(--muted); }
.page-actions { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.5rem; }
.toolbar .field { margin-bottom: 0; min-width: 150px; }

/* ── Auth ── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
    background: radial-gradient(1200px 600px at 70% -10%, rgba(31,111,235,.18), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border);
    border-radius: 16px; padding: 2.5rem 2rem; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.auth-card .sub { color: var(--muted); margin-bottom: 2rem; font-size: .9rem; }
.alert { padding: .7rem .9rem; border-radius: 8px; font-size: .85rem; margin-bottom: 1rem; display: none; }
.alert.error { background: rgba(248,81,73,.12); color: var(--danger); display: block; }
.alert.success { background: rgba(63,185,80,.12); color: var(--accent); display: block; }

.prop-card { display: flex; flex-direction: column; gap: .5rem; }
.prop-card .ndg { font-weight: 700; font-size: .95rem; }
.prop-card .loc { color: var(--muted); font-size: .82rem; }
.prop-card .price { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.section-title { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── Toggle de tema ── */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    background: transparent; border: 1px solid var(--border);
    color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
    font-size: 1.05rem; line-height: 1;
}
.theme-toggle:hover { background: var(--hover); border-color: var(--primary); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
html[data-theme="light"] .theme-toggle .icon-sun { display: inline; }
html[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ── Notificaciones ── */
.notif-wrap { position: relative; }
.notif-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; background: transparent; border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 1.05rem; line-height: 1; position: relative; }
.notif-btn:hover { background: var(--hover); border-color: var(--primary); }
.notif-badge { position: absolute; top: -4px; right: -4px; background: #ef5350; color: #fff; border-radius: 10px; min-width: 16px; height: 16px; padding: 0 4px; font-size: .65rem; font-weight: 700; align-items: center; justify-content: center; }
.notif-panel { display: none; position: absolute; right: 0; top: 46px; width: 320px; max-height: 400px; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.25); z-index: 200; }
.notif-panel.open { display: block; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: .85rem; }
.notif-mark { background: none; border: none; color: var(--primary); cursor: pointer; font-size: .75rem; }
.notif-item { display: block; padding: .65rem .9rem; border-bottom: 1px solid var(--border); font-size: .82rem; color: var(--text); text-decoration: none; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--hover); }
.notif-item.unread { background: rgba(31,111,235,.08); }
