@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --ink: #14201e;
    --muted: #5f7370;
    --bg: #f1f6f5;
    --card: #ffffff;
    --line: #dbe6e3;
    --brand: #0f766e;
    --brand-dark: #0b5a54;
    --brand-light: #d9f2ee;
    --brand-light-hover: #c3e8e2;
    --brand-light-text: #0b5a54;
    --red: #9d3e32;
    --amber: #a86d13;
    --green: #1c7a53;
    --shadow: 0 14px 40px rgba(20, 32, 30, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
button, input, select, textarea { font: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 14px max(20px, calc((100vw - 1120px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(241, 246, 245, .94);
    backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.brand span {
    display: inline-grid; place-items: center; width: 32px; height: 32px;
    background: var(--brand); color: #fff; border-radius: 10px;
}
.topbar nav { display: flex; gap: 20px; }
.topbar nav a { color: var(--ink); font-weight: 600; }
.topbar nav a.active, .topbar nav a:hover { color: var(--brand); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }

.bottom-nav { display: none; }

.link-button, .actions button.link-button {
    border: 0; background: none; color: var(--brand); padding: 0; cursor: pointer;
}
.link-button:hover { color: var(--brand-dark); }

.container { width: min(1120px, calc(100% - 32px)); margin: 34px auto 70px; }
.auth-container { display: grid; min-height: 90vh; place-items: center; }

.login-card {
    width: min(420px, 100%); padding: 42px; background: var(--card);
    border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
}
.login-mark {
    display: inline-grid; place-items: center; width: 54px; height: 54px;
    background: var(--brand); color: #fff; border-radius: 16px;
}
.login-card h1 { margin: 18px 0 4px; }

.stack { display: grid; gap: 18px; }
.muted { color: var(--muted); font-size: 14px; }
label { display: grid; gap: 7px; font-weight: 650; }

input, select, textarea {
    width: 100%; border: 1px solid #c8d6d2; background: #fff;
    padding: 11px 13px; border-radius: 11px; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(15, 118, 110, .15); border-color: var(--brand);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }

button, .button {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: 11px; padding: 11px 16px;
    font-weight: 700; cursor: pointer;
}
.primary { background: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-dark); color: #fff; }
.secondary { background: var(--brand-light); color: var(--brand-light-text); }
.secondary:hover { background: var(--brand-light-hover); }
.danger { background: #f5ded9; color: var(--red); }
.danger:hover { background: #eecbc3; }
.wide { width: 100%; }

.flash { padding: 13px 16px; border-radius: 12px; margin-bottom: 20px; }
.flash.success { background: #dceee6; color: #174c3b; }
.flash.error { background: #f5ded9; color: #812f26; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 0 22px; }
.page-header h1, .page-header h2 { margin: 0; letter-spacing: -.02em; }
.eyebrow { margin: 0 0 3px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-size: 11px; font-weight: 800; }

.card, .form-card {
    background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
}
.form-card { padding: 26px; }
.form-card h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.full { grid-column: 1 / -1; }

.section { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.actions { margin-top: 18px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.actions form { display: inline-flex; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.table-wrap table { min-width: 640px; }
.table-wrap th:first-child, .table-wrap td:first-child { padding-left: 20px; }
.table-wrap th:last-child, .table-wrap td:last-child { padding-right: 20px; }

.badge {
    display: inline-flex; font-size: 11px; line-height: 1; padding: 5px 8px; border-radius: 99px;
    background: var(--brand-light); color: var(--brand-light-text); text-transform: uppercase; letter-spacing: .04em;
}
.badge.role-root { background: #f4e6c9; color: #7c5316; }
.badge.role-admin { background: #dbe4fb; color: #2c4a9e; }
.badge.inactive { background: #eadad6; color: #7b3b32; }

.empty { padding: 50px 20px; text-align: center; color: var(--muted); display: grid; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; }

/* Workspace caso */
.workspace-grid { display: grid; gap: 26px; }
.accordion { display: flex; flex-direction: column; gap: 10px; }
.accordion-item { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--card); }
.accordion-toggle {
    width: 100%; display: flex; justify-content: space-between; align-items: center;
    padding: 13px 16px; background: #f7fbfa; color: var(--ink); border: 0; border-radius: 0;
    font-weight: 650; cursor: pointer;
}
.accordion-toggle:hover { background: var(--brand-light); }
.accordion-panel { display: none; padding: 14px 16px 18px; }
.accordion-item.open .accordion-panel { display: block; }

.conditions-table td, .conditions-table th { padding: 9px 6px; }
.conditions-table button { white-space: nowrap; padding: 7px 11px; font-size: 13px; }

.editor-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.editor-toolbar button {
    min-width: 40px; padding: 7px 10px; background: var(--brand-light); color: var(--brand-light-text);
    border-radius: 9px; font-weight: 700;
}
.editor-toolbar button:hover { background: var(--brand-light-hover); }

.editor {
    min-height: 150px; padding: 12px 14px; border: 1px solid #c8d6d2; border-radius: 12px;
    background: #fff; line-height: 1.5;
}
.editor:empty:before { content: attr(data-placeholder); color: #9aa9a6; }
.district-editor { min-height: 100px; margin-bottom: 10px; }
.district-composer { margin-bottom: 16px; }
.district-composer-title { display: block; margin-bottom: 6px; font-weight: 650; }

.image-grid {
    margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.image-item { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); position: relative; }
.image-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eef4f3; }
.image-item .image-name { display: block; padding: 8px; font-size: 12px; overflow-wrap: anywhere; color: var(--ink); }
.image-item form { position: absolute; top: 6px; right: 6px; }
.image-item .icon-inline-button {
    width: 28px; height: 28px; border-radius: 50%; padding: 0; border: none;
    background: rgba(20, 32, 30, .55); color: #fff; font-size: 14px; line-height: 1;
}
.image-item .icon-inline-button:hover { background: rgba(157, 62, 50, .85); }

.reports-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.reports-list li { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }

.two-columns { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 20px; align-items: start; }

@media (max-width: 820px) {
    .form-grid, .two-columns { grid-template-columns: 1fr; }
    .container { margin-top: 22px; margin-bottom: calc(86px + env(safe-area-inset-bottom)); }
    .topbar { display: none; }
    .bottom-nav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        background: rgba(255, 255, 255, .97); backdrop-filter: blur(12px);
        border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    }
    .bottom-nav-item {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 6px 2px; color: var(--muted); font-size: 10.5px; font-weight: 650; border-radius: 12px;
    }
    .bottom-nav-item svg { width: 22px; height: 22px; }
    .bottom-nav-item.active { color: var(--brand); }
}

@media (max-width: 560px) {
    .brand span:not(:has(svg)) { display: none; }
    .form-card { padding: 20px; }
    .login-card { padding: 28px; }
    .container { width: min(100% - 22px, 1120px); }
}
