:root {
    --bg-1: #f5efe4;
    --bg-2: #faf7f0;
    --ink: #22313f;
    --ink-soft: #5b6f7f;
    --line: rgba(34, 49, 63, 0.16);
    --line-soft: rgba(34, 49, 63, 0.1);
    --card: rgba(255, 255, 255, 0.86);
    --hero: rgba(255, 255, 255, 0.78);
    --sidebar: rgba(255, 255, 255, 0.72);
    --primary: #118b8d;
    --blue: #2f6c9e;
    --danger: #d64545;
    --danger-dark: #8f2222;
    --success: #1f9c57;
    --warning: #cc7a00;
    --shadow: 0 16px 36px rgba(20, 38, 54, 0.14);
}

[data-theme="dark"] {
    --bg-1: #12191f;
    --bg-2: #1c2630;
    --ink: #e8eef3;
    --ink-soft: #9eb1c0;
    --line: rgba(158, 177, 192, 0.22);
    --line-soft: rgba(158, 177, 192, 0.15);
    --card: rgba(24, 35, 45, 0.92);
    --hero: rgba(24, 35, 45, 0.84);
    --sidebar: rgba(18, 27, 35, 0.88);
    --shadow: 0 20px 42px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    min-height: 100vh;
    background:
        radial-gradient(circle at 8% 12%, rgba(17, 139, 141, 0.18), transparent 30%),
        radial-gradient(circle at 86% 0%, rgba(241, 143, 1, 0.16), transparent 32%),
        linear-gradient(150deg, var(--bg-1) 0%, var(--bg-2) 56%, #ffffff 100%);
}

a { color: inherit; }

.hidden { display: none !important; }

.app-shell {
    display: flex;
    align-items: flex-start;
    gap: 22px;
    padding: 22px 18px 28px;
}

.sidebar {
    width: 258px;
    flex: 0 0 258px;
    position: sticky;
    top: 22px;
    align-self: flex-start;
    background: var(--sidebar);
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 26px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    padding: 22px 14px 14px;
    z-index: 20;
}

.brand {
    margin: 0 4px 20px;
    padding: 2px 6px 16px;
    border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--primary);
    font-weight: 800;
    margin-bottom: 12px;
}
.brand-title {
    font-size: 1.22rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--ink);
}
.brand-copy {
    margin-top: 8px;
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

.side-nav {
    display: grid;
    gap: 6px;
    margin-bottom: 18px;
}

.side-group { position: relative; }

.side-group-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 46px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    color: var(--ink);
    text-align: left;
    font: inherit;
    cursor: pointer;
    transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.side-group-toggle:hover,
.side-group.is-open > .side-group-toggle,
.side-group.has-active > .side-group-toggle {
    background: rgba(17, 139, 141, 0.09);
    border-color: var(--line-soft);
}

.side-group-label { flex: 1; font-size: 0.9rem; font-weight: 750; }

.side-group-count {
    display: inline-grid;
    min-width: 22px;
    height: 22px;
    place-items: center;
    border-radius: 8px;
    background: rgba(34, 49, 63, 0.07);
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 800;
}

.side-group-arrow {
    color: var(--ink-soft);
    font-size: 1.35rem;
    line-height: 1;
    transition: transform .18s ease;
}

.side-group.is-open .side-group-arrow { transform: rotate(90deg); }

.side-submenu {
    position: absolute;
    top: -4px;
    left: calc(100% + 13px);
    z-index: 30;
    display: none;
    width: 238px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.side-group.is-open .side-submenu { display: grid; gap: 5px; }

.side-submenu-heading {
    padding: 5px 9px 8px;
    color: var(--ink-soft);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.side-link {
    text-decoration: none;
    color: var(--ink);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 11px;
    padding: 11px 10px;
    transition: transform .18s ease, border-color .2s ease, background .2s ease;
}

[data-theme="dark"] .side-link {
    background: rgba(255, 255, 255, 0.04);
}

.side-link:hover {
    transform: translateX(3px);
    border-color: rgba(17, 139, 141, 0.3);
    background: rgba(17, 139, 141, 0.08);
}

.side-link.active {
    background: linear-gradient(145deg, rgba(17, 139, 141, 0.18), rgba(47, 108, 158, 0.18));
    border-color: rgba(17, 139, 141, 0.28);
}

.side-link-title {
    display: block;
    font-size: 0.88rem;
    font-weight: 800;
}

.side-link-copy {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--ink-soft);
    line-height: 1.45;
}

.account-card {
    border-radius: 18px;
    background: rgba(17, 41, 59, 0.045);
    border: 1px solid var(--line-soft);
    padding: 14px;
}

.account-label,
.account-role {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.account-name {
    margin: 6px 0 4px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--ink);
}

.logout-link {
    display: inline-flex;
    margin-top: 12px;
    text-decoration: none;
    color: var(--ink);
    font-weight: 800;
}

.container {
    flex: 1;
    max-width: 1280px;
    padding-bottom: 34px;
}

.hero,
.card-panel,
.table-card {
    background: var(--hero);
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.hero {
    padding: 20px;
    margin-bottom: 14px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

h1, .title {
    margin: 0;
    font-size: clamp(1.35rem, 2.8vw, 2rem);
    line-height: 1.2;
}

.subtitle {
    margin-top: 7px;
    color: var(--ink-soft);
    font-size: 0.94rem;
}

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.box,
.card-panel {
    background: var(--card);
    border: 1px solid var(--line-soft);
}

.box {
    border-radius: 13px;
    box-shadow: 0 8px 18px rgba(20, 38, 54, 0.08);
    padding: 12px;
}

.summary-label {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
    margin-bottom: 4px;
}

.summary-value {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
}

.section-title {
    margin: 18px 0 10px;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    font-weight: 800;
}

.card-panel {
    padding: 18px;
    margin-bottom: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.field {
    display: grid;
    gap: 6px;
}

.field label {
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.92);
    padding: 11px 12px;
    font-size: 0.95rem;
    color: var(--ink);
}

[data-theme="dark"] .field input,
[data-theme="dark"] .field select,
[data-theme="dark"] .field textarea {
    background: rgba(255, 255, 255, 0.05);
}

.field textarea {
    min-height: 120px;
    resize: vertical;
    font-family: Consolas, monospace;
}

.field-hint {
    font-size: 0.76rem;
    color: var(--ink-soft);
    line-height: 1.45;
}

.form-actions,
.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.form-actions { margin-top: 14px; }
.toolbar { margin-bottom: 14px; }

.toolbar .field {
    min-width: 180px;
    margin: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    border: none;
    border-radius: 11px;
    padding: 11px 16px;
    font-size: 0.9rem;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(130deg, var(--primary), var(--blue));
    cursor: pointer;
}

.btn-secondary { background: #41586a; }
.btn-danger { background: linear-gradient(130deg, var(--danger), var(--danger-dark)); }
.btn-ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.btn:disabled {
    opacity: 0.72;
    cursor: wait;
}

.table-card {
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: rgba(17, 139, 141, 0.12);
    color: #1f3648;
    text-align: left;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 12px;
}

td {
    padding: 12px;
    border-top: 1px solid var(--line-soft);
    font-size: 0.92rem;
    vertical-align: top;
}

.mono { font-family: Consolas, monospace; word-break: break-all; }

.badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    background: rgba(47, 108, 158, 0.14);
    color: #235177;
    border: 1px solid rgba(47, 108, 158, 0.24);
}

.status-agendada { background: rgba(204, 122, 0, 0.14); color: #7a4a00; }
.status-executada,
.status-atendida { background: rgba(31, 156, 87, 0.15); color: #0f6f3b; }
.status-em_andamento,
.status-pausada,
.status-chamando { background: rgba(17, 139, 141, 0.16); color: #0e6162; }
.status-erro,
.status-cancelada,
.status-nao_atendeu,
.status-ocupado { background: rgba(214, 69, 69, 0.16); color: #8e2929; }

.actions-cell {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.pagination {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    margin-top: 12px;
}

.pagination-info {
    color: var(--ink-soft);
    font-size: 0.84rem;
    margin-right: auto;
}

.toast-container {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1200;
    display: grid;
    gap: 10px;
}

.toast {
    min-width: 240px;
    max-width: 360px;
    padding: 12px 14px;
    border-radius: 14px;
    color: #fff;
    box-shadow: var(--shadow);
    animation: fadeUp .22s ease;
}

.toast-success { background: linear-gradient(130deg, #1f9c57, #158046); }
.toast-error { background: linear-gradient(130deg, #d64545, #8f2222); }
.toast-info { background: linear-gradient(130deg, #2f6c9e, #254f74); }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 32, 0.35);
    backdrop-filter: blur(3px);
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-card {
    display: grid;
    gap: 12px;
    justify-items: center;
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: 18px;
    padding: 22px 26px;
    box-shadow: var(--shadow);
}

.loading-spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid rgba(17, 139, 141, 0.16);
    border-top-color: var(--primary);
    animation: spin .9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-weight: 700;
    color: var(--ink);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 32, 0.4);
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.modal-card {
    width: min(440px, 100%);
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.modal-copy {
    color: var(--ink-soft);
    line-height: 1.5;
}

.modal-actions {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.theme-switch {
    margin-top: 12px;
    width: 100%;
}

@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
        padding: 12px;
        gap: 14px;
    }

    .sidebar {
        width: 100%;
        flex: auto;
        position: static;
        padding: 16px;
    }

    .brand { margin-bottom: 12px; }
    .side-nav { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
    .side-submenu {
        position: static;
        width: 100%;
        margin-top: 4px;
        box-shadow: none;
        backdrop-filter: none;
    }
}
