:root {
    --brand-primary: #123b5d;
    --brand-secondary: #247a80;
    --brand-accent: #c57910;
    --ink: #163042;
    --muted: #5f7481;
    --surface: #ffffff;
    --surface-soft: #f4f7f9;
    --border: #d6e1e6;
    --danger: #9a3029;
    --success: #12664f;
    color: var(--ink);
    background: var(--surface-soft);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
    line-height: 1.5;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top right, color-mix(in srgb, var(--brand-secondary) 13%, transparent), transparent 34%),
        var(--surface-soft);
}

[hidden] {
    display: none !important;
}

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

button,
a {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--brand-primary);
}

img,
svg {
    max-width: 100%;
}

code {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    overflow-wrap: anywhere;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 1000;
    padding: 10px 14px;
    border-radius: 8px;
    background: #ffffff;
    color: #102d46;
    font-weight: 800;
    transform: translateY(-150%);
}

.skip-link:focus {
    transform: translateY(0);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    min-height: 76px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px clamp(20px, 4vw, 56px);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
}

.topbar form {
    margin: 0;
}

.brand {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 13px;
    background: var(--brand-primary);
    color: #ffffff;
    font-weight: 900;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: #667d89;
}

.main-nav {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.main-nav a {
    padding: 9px 11px;
    border-radius: 9px;
    color: #29495c;
    font-size: 0.92rem;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
}

.main-nav a:hover,
.main-nav a[aria-current="page"] {
    background: #eaf1f4;
    color: var(--brand-primary);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 52px 0 64px;
}

.hero {
    max-width: 760px;
    margin-bottom: 34px;
}

.eyebrow {
    color: var(--brand-secondary);
    font-size: 0.78rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
    color: var(--brand-primary);
    text-wrap: balance;
}

h1 {
    margin: 0.3em 0;
    font-size: clamp(2.2rem, 6vw, 4.5rem);
    line-height: 1.02;
    letter-spacing: -0.04em;
}

h2 {
    font-size: 1.45rem;
}

.lead {
    color: #4d6675;
    font-size: 1.15rem;
    line-height: 1.65;
}

.muted,
.form-hint {
    color: var(--muted);
}

.card {
    padding: 26px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 16px 48px rgba(18, 59, 93, 0.08);
}

.auth-grid,
.install-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr);
    gap: 34px;
    align-items: start;
}

.cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.form,
.admin-form,
.settings-form {
    display: grid;
    gap: 17px;
}

.form h2,
.admin-form h2,
.settings-form h2 {
    margin: 6px 0;
}

label {
    color: #395667;
    font-weight: 750;
}

.form label,
.admin-form label,
.settings-form label,
.dialog-shell label {
    display: grid;
    gap: 7px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 11px 13px;
    border: 1px solid #b9ccd5;
    border-radius: 10px;
    outline: none;
    background: #ffffff;
    color: var(--ink);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-secondary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-secondary) 19%, transparent);
}

input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

input[type="checkbox"] {
    width: 19px;
    min-height: 19px;
    accent-color: var(--brand-primary);
}

input[type="file"] {
    padding: 10px;
}

small {
    color: #657c89;
    font-weight: 450;
}

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

.recurrence-cols {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    border: 1px solid transparent;
    border-radius: 11px;
    cursor: pointer;
    font-weight: 820;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.button:hover:not(:disabled) {
    filter: brightness(0.96);
}

.button.primary,
.primary.button {
    background: var(--brand-primary);
    color: #ffffff;
}

.button.ghost,
.ghost.button {
    border-color: #d5e1e6;
    background: #edf3f6;
    color: var(--brand-primary);
}

.compact-button {
    min-height: 38px;
    padding: 8px 12px;
    white-space: nowrap;
}

.alert {
    margin-bottom: 22px;
    padding: 14px 16px;
    border-radius: 12px;
    font-weight: 750;
}

.alert.success {
    border: 1px solid #bde6d8;
    background: #dff7ef;
    color: var(--success);
}

.alert.error,
.form-error {
    border: 1px solid #f2c7c3;
    background: #ffe7e5;
    color: #842821;
}

.checks {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.checks li {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checks span {
    display: grid;
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    color: #ffffff;
    font-weight: 900;
}

.checks .ok span {
    background: #18744f;
}

.checks .ko span {
    background: #a6322a;
}

.dashboard-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
}

.dashboard-head h1 {
    font-size: clamp(2.2rem, 5vw, 3.8rem);
}

.sync-status {
    padding: 9px 13px;
    border-radius: 999px;
    background: #eaf1f4;
    color: #466575;
    font-size: 0.85rem;
    font-weight: 800;
    white-space: nowrap;
}

.sync-status[data-state="loading"] {
    background: #fff1c9;
    color: #6b4a08;
}

.sync-status[data-state="error"] {
    background: #ffe7e5;
    color: #842821;
}

.sync-status[data-state="success"] {
    background: #dff7ef;
    color: var(--success);
}

.metrics-grid {
    margin-bottom: 32px;
}

.metric-card h2 {
    margin-top: 0;
    font-size: 1.05rem;
}

.metric-card p {
    margin-bottom: 0;
}

.metric {
    display: block;
    margin: 16px 0;
    color: var(--brand-secondary);
    font-size: 2.5rem;
    font-weight: 850;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(180px, 2fr) repeat(5, minmax(110px, 1fr)) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 24px;
    padding: 18px;
}

.filter-bar label {
    display: grid;
    gap: 6px;
    color: #506a78;
    font-size: 0.78rem;
    font-weight: 800;
}

.checkbox-field {
    display: flex !important;
    min-height: 44px;
    align-items: center;
    gap: 8px !important;
    padding: 8px 0;
    white-space: nowrap;
}

.danger-choice {
    color: var(--danger);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(290px, 0.8fr);
    gap: 24px;
    align-items: start;
}

.dashboard-main {
    min-width: 0;
}

.dashboard-sidebar {
    position: sticky;
    top: 100px;
    display: grid;
    gap: 24px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.section-heading h2 {
    margin: 0.2rem 0 0;
    font-size: 1.65rem;
}

.section-heading p {
    margin: 0;
    color: #667d89;
}

.kanban {
    display: grid;
    grid-template-columns: repeat(3, minmax(245px, 1fr));
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.kanban-column {
    min-width: 245px;
    padding: 14px;
    border: 1px solid #cedce2;
    border-radius: 18px;
    background: #eaf0f3;
}

.kanban-column > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px 13px;
}

.kanban-column h3 {
    margin: 0;
    font-size: 1rem;
}

.column-count {
    display: grid;
    min-width: 28px;
    height: 28px;
    place-items: center;
    padding: 0 8px;
    border-radius: 999px;
    background: #ffffff;
    color: var(--brand-primary);
    font-weight: 850;
}

.kanban-list {
    display: grid;
    min-height: 180px;
    gap: 10px;
    border-radius: 13px;
    transition: background 0.18s, padding 0.18s;
}

.kanban-list.is-over {
    padding: 6px;
    background: color-mix(in srgb, var(--brand-secondary) 14%, transparent);
}

.kanban-card {
    padding: 14px;
    border: 1px solid #d3e0e6;
    border-left: 4px solid #889da8;
    border-radius: 13px;
    background: #ffffff;
    box-shadow: 0 7px 20px rgba(18, 59, 93, 0.07);
    cursor: grab;
}

.kanban-card:active {
    cursor: grabbing;
}

.kanban-card.is-dragging {
    opacity: 0.48;
    transform: rotate(1deg);
}

.kanban-card.priority-high {
    border-left-color: var(--brand-accent);
}

.kanban-card.priority-urgent {
    border-left-color: #b83830;
}

.kanban-card.priority-low {
    border-left-color: #56866a;
}

.card-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.priority-label {
    color: #627987;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.type-badge {
    padding: 4px 7px;
    border-radius: 999px;
    background: #eaf1f4;
    color: #29495c;
    font-size: 0.7rem;
    font-weight: 900;
}

.type-call {
    background: #dcecff;
}

.type-message {
    background: #eee3ff;
}

.kanban-card h4 {
    margin: 10px 0 7px;
    font-size: 1rem;
}

.kanban-card p {
    margin: 0 0 12px;
    color: #526c7a;
    font-size: 0.88rem;
    line-height: 1.5;
}

.client-line {
    font-weight: 700;
}

.kanban-card > footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #657c89;
    font-size: 0.75rem;
}

.kanban-empty {
    margin: 52px 0;
    color: #728894;
    font-size: 0.85rem;
    text-align: center;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 11px;
}

.card-open,
.link-button {
    min-height: 34px;
    padding: 5px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--brand-primary);
    cursor: pointer;
    font-weight: 800;
}

.card-open:hover,
.link-button:hover {
    background: #edf3f6;
}

.card-move {
    width: 36px;
    height: 34px;
    border: 1px solid #cbd9df;
    border-radius: 8px;
    background: #f4f7f9;
    color: var(--brand-primary);
    cursor: pointer;
    font-weight: 900;
}

.kanban-column:first-child .card-move[data-direction="previous"],
.kanban-column:last-child .card-move[data-direction="next"] {
    visibility: hidden;
}

.panel-title,
.dialog-shell header,
.dialog-shell footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.notification-panel h2,
.performance-panel h2,
.activity-panel h2 {
    margin: 0.35rem 0 1rem;
    font-size: 1.35rem;
}

.notification-count {
    display: inline-grid;
    min-width: 25px;
    height: 25px;
    place-items: center;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--brand-accent);
    color: #16120b;
    font-size: 0.8rem;
}

.notification-list,
.activity-list {
    display: grid;
    max-height: 470px;
    margin: 0;
    padding: 0;
    overflow: auto;
    list-style: none;
}

.notification-list li {
    padding: 13px 0;
    border-top: 1px solid #e2eaee;
}

.notification-list li.is-unread {
    padding-left: 10px;
    border-left: 3px solid var(--brand-secondary);
}

.notification-list p {
    margin: 0 0 4px;
    color: #435f6f;
    font-size: 0.88rem;
}

.notification-list time,
.activity-list time {
    color: #748994;
    font-size: 0.72rem;
}

.stats-list {
    display: grid;
    gap: 0;
    margin: 0;
}

.stats-list > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 0;
    border-top: 1px solid #e2eaee;
}

.stats-list dt {
    color: #526c7a;
}

.stats-list dd {
    margin: 0;
    color: var(--brand-primary);
    font-weight: 900;
}

.activity-list li {
    display: grid;
    grid-template-columns: 12px 1fr;
    gap: 10px;
    padding: 13px 0;
    border-top: 1px solid #e2eaee;
}

.activity-dot {
    width: 8px;
    height: 8px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--brand-secondary);
}

.activity-list strong {
    color: var(--brand-primary);
    font-size: 0.83rem;
}

.activity-list p {
    margin: 2px 0;
    color: #526c7a;
    font-size: 0.84rem;
    line-height: 1.45;
}

.empty-activity,
.empty-notification {
    display: block !important;
    color: #657c89;
    font-size: 0.85rem;
}

.app-dialog {
    width: min(650px, calc(100% - 24px));
    max-height: calc(100vh - 32px);
    padding: 0;
    overflow: auto;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(16, 45, 70, 0.4);
}

.app-dialog::backdrop {
    background: rgba(16, 45, 70, 0.52);
}

.dialog-shell {
    display: grid;
    gap: 16px;
    padding: 24px;
}

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

.dialog-shell [data-fields] {
    display: grid;
    gap: 14px;
}

.dialog-close {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    background: #edf3f6;
    color: var(--brand-primary);
    cursor: pointer;
    font-size: 1.5rem;
}

.form-error {
    padding: 10px 12px;
    border-radius: 9px;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.6fr);
    gap: 24px;
    align-items: start;
    margin-bottom: 24px;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #e0e9ed;
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: #4b6675;
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.audit-context {
    display: block;
    max-width: 340px;
    white-space: pre-wrap;
    word-break: break-word;
}

.settings-form {
    max-width: 900px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.offline-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
}

.offline-card {
    width: min(520px, 100%);
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--brand-secondary) 42%, #ffffff);
    outline-offset: 2px;
}

@media (max-width: 1100px) {
    .filter-bar {
        grid-template-columns: repeat(4, minmax(130px, 1fr));
    }

    .search-field {
        grid-column: span 2;
    }

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

    .dashboard-sidebar {
        position: static;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .notification-panel,
    .activity-panel {
        grid-column: span 1;
    }
}

@media (max-width: 850px) {
    .topbar {
        position: static;
        min-height: auto;
        flex-wrap: wrap;
        padding: 12px 18px;
    }

    .main-nav {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        padding-top: 4px;
        border-top: 1px solid #e2eaee;
    }

    .auth-grid,
    .install-grid,
    .cards,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-head,
    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .dashboard-sidebar {
        grid-template-columns: 1fr;
    }

    .filter-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .search-field {
        grid-column: span 2;
    }

    .recurrence-cols {
        grid-template-columns: 1fr;
    }

    .kanban {
        grid-template-columns: repeat(3, minmax(260px, 1fr));
        margin-right: -16px;
        padding-right: 16px;
    }
}

@media (max-width: 560px) {
    .shell {
        width: min(100% - 20px, 1180px);
        padding-top: 32px;
    }

    .brand small {
        display: none;
    }

    .compact-button {
        padding-inline: 10px;
        font-size: 0.84rem;
    }

    .card {
        padding: 20px;
    }

    .cols,
    .filter-bar {
        grid-template-columns: 1fr;
    }

    .search-field {
        grid-column: auto;
    }

    .head-actions {
        width: 100%;
        align-items: stretch;
    }

    .head-actions .button,
    .head-actions .sync-status {
        flex: 1 1 auto;
    }

    .dashboard-head h1 {
        font-size: 2.2rem;
    }

    .lead {
        font-size: 1rem;
    }

    .kanban {
        margin-right: -10px;
        padding-right: 10px;
    }

    .dialog-shell header,
    .dialog-shell footer,
    .panel-title {
        align-items: flex-start;
    }

    .dialog-shell footer {
        flex-direction: column-reverse;
    }

    .dialog-shell footer .button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}

@media print {
    .topbar,
    .head-actions,
    .filter-bar,
    .card-actions,
    .button {
        display: none !important;
    }

    .shell {
        width: 100%;
        padding: 0;
    }

    .card {
        box-shadow: none;
    }
}

.install-fieldset {
    display: contents;
}

.install-fieldset:disabled {
    opacity: 0.65;
}
