:root {
    --bg: #f5f7f8;
    --ink: #16202a;
    --muted: #667383;
    --line: #dce3e8;
    --panel: #ffffff;
    --teal: #0f766e;
    --teal-dark: #0b5f59;
    --blue: #27548a;
    --amber: #b7791f;
    --red: #b42318;
    --green: #14703a;
    --shadow: 0 18px 42px rgba(22, 32, 42, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    line-height: 1.35;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 54px;
    padding: 0 18px;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    min-width: 180px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 900;
    letter-spacing: 0;
}

.brand-mark.small {
    width: 32px;
    height: 32px;
    font-size: 12px;
}

.menu-toggle {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 90;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 74px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    box-shadow: 0 14px 34px rgba(22, 32, 42, .22);
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
}

.menu-toggle.open,
.menu-toggle:hover {
    background: var(--teal-dark);
}

.floating-menu {
    position: fixed;
    right: 14px;
    bottom: 62px;
    z-index: 89;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 198px;
    gap: 5px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 18px 42px rgba(22, 32, 42, .18);
    backdrop-filter: blur(14px);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px) scale(.98);
    transition: opacity .16s ease, transform .16s ease;
}

.floating-menu.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.floating-menu a,
.logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 6px 7px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.floating-menu a.active,
.floating-menu a:hover,
.logout:hover {
    background: #eaf0f2;
    color: var(--ink);
}

.floating-menu .logout {
    grid-column: 1 / -1;
    color: var(--red);
}

.layout {
    width: min(1180px, calc(100% - 32px));
    margin: 18px auto 36px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 12px;
}

.page-head h1,
.person-card h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 38px);
    line-height: 1.02;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--teal);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.metric-grid article,
.panel,
.person-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric-grid article {
    padding: 12px;
}

.metric-grid span,
.muted,
small {
    color: var(--muted);
}

.metric-grid strong {
    display: block;
    margin-top: 5px;
    font-size: 26px;
    line-height: 1;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(320px, .8fr);
    gap: 12px;
}

.dashboard-split {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
}

.dashboard-split .panel {
    min-height: 172px;
}

.dashboard-split .panel:first-child {
    min-width: 0;
}

.dashboard-split .panel:first-child .table-wrap {
    max-height: 420px;
    overflow: auto;
}

.dashboard-split .panel:last-child {
    position: sticky;
    top: 66px;
}

.panel {
    padding: 14px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

h2,
h3,
p {
    margin-top: 0;
}

h2 {
    margin-bottom: 10px;
    font-size: 18px;
}

.primary,
.secondary,
.ghost,
.tiny {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
}

.tiny {
    min-height: 26px;
    padding: 4px 7px;
    font-size: 11px;
}

.primary {
    background: var(--teal);
    color: #fff;
}

.primary:hover {
    background: var(--teal-dark);
}

.secondary,
.ghost,
.tiny {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.secondary:hover,
.ghost:hover,
.tiny:hover {
    background: #eef3f5;
}

.danger-action {
    color: var(--red);
    border-color: #f0c3bd;
}

.danger-action:hover {
    background: #fff0ee;
}

.wide {
    width: 100%;
}

.button-row,
.send-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.send-row {
    margin-top: 10px;
}

.alert {
    margin-bottom: 10px;
    padding: 9px 11px;
    border-radius: 8px;
    font-weight: 700;
}

.alert.success {
    background: #e8f7ef;
    color: var(--green);
    border: 1px solid #b9e5cb;
}

.alert.danger {
    background: #fff0ee;
    color: var(--red);
    border: 1px solid #f5c5bd;
}

.call-screen {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
    gap: 12px;
}

.person-card {
    padding: 16px;
    min-height: 420px;
}

.person-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.role,
.source {
    display: inline-flex;
    padding: 5px 8px;
    border-radius: 6px;
    background: #e9f2f1;
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 900;
}

.source {
    background: #f4ead9;
    color: var(--amber);
}

.phone-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 14px 0;
    padding: 12px;
    border-radius: 8px;
    background: #17202a;
    color: #fff;
}

.phone-box span {
    font-size: clamp(20px, 3vw, 30px);
    font-weight: 900;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.phone-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.phone-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 31px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-size: 12px;
    font-weight: 900;
}

.phone-actions a:hover {
    background: #eaf0f2;
}

.details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
}

.details div {
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fafcfd;
}

.details dt {
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
}

.details dd {
    margin: 3px 0 0;
    font-weight: 800;
}

.last-note {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.last-note p {
    margin: 7px 0 0;
}

.sync-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin: 0 0 10px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #e9f2f1;
    color: var(--teal-dark);
    font-size: 11px;
    font-weight: 900;
}

.sync-status.syncing {
    background: #fff4df;
    color: var(--amber);
}

.sync-status.warn {
    background: #fff0ee;
    color: var(--red);
}

.sync-status.ok {
    background: #e9f2f1;
    color: var(--teal-dark);
}

.stack {
    display: grid;
    gap: 10px;
}

label {
    display: grid;
    gap: 5px;
}

label span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5dc;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 8px 9px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(15, 118, 110, .18);
    border-color: var(--teal);
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 660px;
}

th {
    text-align: left;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

th,
td {
    padding: 7px 8px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

td small {
    display: block;
    margin-top: 1px;
    font-size: 11px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    min-width: 126px;
}

.row-actions form {
    margin: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #edf1f4;
    color: var(--ink);
    font-size: 11px;
    font-weight: 900;
}

.badge.good {
    background: #e3f4eb;
    color: var(--green);
}

.badge.bad {
    background: #fdebe8;
    color: var(--red);
}

.badge.process {
    background: #e8eff8;
    color: var(--blue);
}

.badge.wait {
    background: #fff4df;
    color: var(--amber);
}

.next-card {
    display: grid;
    gap: 6px;
}

.next-card h3 {
    margin: 0;
    font-size: 22px;
}

.empty,
.empty-state {
    color: var(--muted);
}

.empty-state {
    text-align: center;
    padding: 28px 14px;
}

.settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
    gap: 12px;
}

.edit-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.danger-zone {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.detail-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 8px;
    border-radius: 8px;
    background: #f2f6f7;
}

.detail-strip span {
    color: var(--muted);
}

.field-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check {
    display: flex;
    align-items: center;
    gap: 7px;
    padding-top: 22px;
}

.check input {
    width: 16px;
    height: 16px;
}

.cron-url {
    display: block;
    margin: 10px 0;
    padding: 8px;
    border-radius: 6px;
    background: #101820;
    color: #dbeafe;
    overflow-wrap: anywhere;
}

.pwa-status {
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f6faf9;
    color: var(--teal-dark);
    font-weight: 800;
}

.toolbar-form {
    display: flex;
    align-items: end;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f4f7f9 0%, #eaf1ef 52%, #f7f1e7 100%);
}

.login-shell {
    width: min(390px, calc(100% - 28px));
}

.login-panel {
    padding: 22px;
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-panel h1 {
    margin-bottom: 6px;
    font-size: 26px;
}

.login-panel p {
    color: var(--muted);
}

@media (max-width: 900px) {
    body {
        padding-bottom: 76px;
    }

    .topbar {
        align-items: center;
        flex-direction: row;
        min-height: 50px;
        padding: 8px 12px;
    }

    .menu-toggle {
        right: 12px;
        bottom: 12px;
        min-width: 66px;
        min-height: 36px;
        padding: 7px 10px;
        font-size: 12px;
    }

    .floating-menu {
        right: 12px;
        bottom: 56px;
        width: 184px;
        gap: 4px;
        padding: 7px;
    }

    .floating-menu a {
        min-height: 29px;
        padding: 5px 6px;
        font-size: 11px;
    }

    .logo {
        min-width: 0;
        max-width: calc(100% - 72px);
    }

    .logo span:last-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .page-head,
    .split,
    .call-screen,
    .settings-grid,
    .edit-grid,
    .metric-grid,
    .field-pair {
        grid-template-columns: 1fr;
    }

    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .metric-grid {
        display: grid;
    }

    .dashboard-split .panel:last-child {
        position: static;
    }

    .dashboard-split .panel:first-child .table-wrap {
        max-height: 320px;
    }

    .details {
        grid-template-columns: 1fr;
    }

    .phone-box {
        align-items: flex-start;
        flex-direction: column;
    }

    .phone-actions {
        justify-content: flex-start;
        width: 100%;
    }
}

@media (max-width: 560px) {
    .layout {
        width: min(100% - 18px, 1180px);
        margin-top: 12px;
    }

    .panel,
    .person-card {
        padding: 12px;
    }

    .phone-box span {
        font-size: 22px;
    }

    .button-row,
    .toolbar-form,
    .send-row {
        align-items: stretch;
        flex-direction: column;
    }

    .button-row > *,
    .toolbar-form > *,
    .send-row > * {
        width: 100%;
    }
}
