:root {
    --app-bg: #f6f4f1;
    --card-bg: #ffffff;
    --card-border: #ebe4dd;
    --card-shadow: 0 16px 40px rgba(62, 35, 22, 0.08);
    --accent: #ff6a63;
    --accent-soft: rgba(255, 106, 99, 0.12);
    --ink: #1f1d1a;
    --muted: #6b665f;
    --sidebar-width: 260px;
    --radius-xl: 24px;
    --radius-lg: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(255, 176, 147, 0.28), transparent 28%),
        linear-gradient(180deg, #fbf9f6 0%, var(--app-bg) 100%);
    color: var(--ink);
    font-family: 'Inter', sans-serif;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    position: sticky;
    top: 0;
    flex-direction: column;
    justify-content: space-between;
    width: var(--sidebar-width);
    min-height: 100vh;
    padding: 28px 18px;
    background: rgba(255, 255, 255, 0.82);
    border-right: 1px solid rgba(227, 219, 210, 0.9);
    backdrop-filter: blur(18px);
}

.brand {
    color: var(--accent);
    font-family: 'Nunito Sans', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.06em;
    text-decoration: none;
}

.sidebar .nav-link {
    padding: 0.95rem 1rem;
    border-radius: 16px;
    color: var(--ink);
    font-weight: 500;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.sidebar-footer {
    padding-top: 24px;
    border-top: 1px solid var(--card-border);
}

.content-area {
    flex: 1;
    padding: 32px 28px 40px;
}

.page-header {
    display: flex;
    gap: 18px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: clamp(2rem, 3vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.04em;
}

.eyebrow {
    color: var(--accent);
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.last-updated {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 170px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--card-border);
    border-radius: 16px;
}

.btn-refresh {
    padding: 0.88rem 1.15rem;
    background: var(--accent);
    border: 0;
    border-radius: 16px;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 12px 24px rgba(255, 106, 99, 0.28);
}

.btn-refresh:disabled {
    opacity: 0.7;
    cursor: wait;
}

.card-panel,
.kpi-card {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--card-shadow);
}

.filters-panel {
    padding: 22px;
}

.form-label {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
}

.form-select {
    min-height: 48px;
    border-color: #ddd2c8;
    border-radius: 14px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
}

.kpi-card {
    width: 100%;
    padding: 22px;
    text-align: left;
}

.kpi-card-button {
    border: 1px solid var(--card-border);
    color: inherit;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.kpi-card-static {
    border: 1px solid var(--card-border);
}

.kpi-card-button:hover,
.kpi-card-button:focus {
    transform: translateY(-2px);
    outline: 0;
    box-shadow: 0 20px 46px rgba(62, 35, 22, 0.13);
}

.kpi-label {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 1rem;
}

.kpi-value-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kpi-value {
    font-size: 2.35rem;
    font-weight: 700;
    letter-spacing: -0.05em;
}

.kpi-context {
    margin-top: 10px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.delta {
    display: inline-flex;
    align-items: center;
    padding: 0.34rem 0.6rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.delta--up {
    background: rgba(34, 166, 115, 0.12);
    color: #1f7a5c;
}

.delta--down {
    background: rgba(242, 95, 76, 0.12);
    color: #c03c31;
}

.delta--flat {
    background: rgba(91, 141, 239, 0.12);
    color: #4469bc;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1.2fr) minmax(280px, 0.8fr);
    gap: 16px;
}

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

.dashboard-column-width {
    width: calc((100% - 32px) / 3);
}

.chart-panel,
.side-panel,
.table-panel {
    padding: 22px;
}

.panel-header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 18px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.panel-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
}

.badge-soft {
    padding: 0.45rem 0.72rem;
    background: var(--accent-soft);
    border-radius: 999px;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
}

.chart-wrap {
    position: relative;
    min-height: 280px;
}

.chart-wrap-sm {
    min-height: 190px;
}

.chart-wrap-lg {
    min-height: 320px;
}

.chart-panel-sm {
    padding-bottom: 16px;
}

.executor-list,
.summary-grid,
#customer-activity {
    display: grid;
    gap: 12px;
}

.executor-list,
#customer-activity {
    max-height: 430px;
    padding-right: 4px;
    overflow-y: auto;
}

.executor-card,
.summary-card,
.customer-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(251, 247, 242, 0.92);
    border-radius: 16px;
}

.executor-card p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.customer-card h3 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.customer-card p,
.customer-stats span,
.summary-card span {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.customer-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: right;
}

.customer-card-button {
    width: 100%;
    border: 0;
    color: inherit;
    text-align: left;
    transition: transform 0.18s ease, background 0.18s ease;
}

.executor-card-button {
    width: 100%;
    border: 0;
    color: inherit;
    text-align: left;
    transition: transform 0.18s ease, background 0.18s ease;
}

.customer-card-button:hover,
.customer-card-button:focus,
.executor-card-button:hover,
.executor-card-button:focus {
    background: rgba(255, 106, 99, 0.08);
    outline: 0;
    transform: translateY(-1px);
}

.table-panel table {
    --bs-table-bg: transparent;
}

.kplus-table-wrap {
    max-height: 430px;
    overflow: auto;
}

.compact-ticket-table {
    --bs-table-bg: transparent;
    font-size: 0.9rem;
}

.compact-ticket-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(255, 255, 255, 0.92);
}

.compact-ticket-table td,
.compact-ticket-table th {
    padding: 0.72rem 0.55rem;
}

.compact-muted {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.78rem;
}

.table-panel thead th {
    padding-top: 0.9rem;
    padding-bottom: 0.9rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
}

.table-panel tbody td {
    padding-top: 1rem;
    padding-bottom: 1rem;
    border-color: rgba(227, 219, 210, 0.8);
}

.ticket-row {
    cursor: pointer;
}

.ticket-row:hover,
.ticket-row:focus {
    background: rgba(255, 106, 99, 0.06);
    outline: 0;
}

.table-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.table-title-wrap span {
    color: var(--muted);
    font-size: 0.88rem;
}

.note-preview {
    display: -webkit-box;
    max-width: 260px;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.ticket-code {
    font-weight: 700;
    color: var(--accent);
}

.status-badge {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    padding: 0.42rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status-badge--new {
    background: rgba(91, 141, 239, 0.14);
    color: #4469bc;
}

.status-badge--open {
    background: rgba(245, 183, 0, 0.16);
    color: #8f6500;
}

.status-badge--in_progress {
    background: rgba(242, 95, 76, 0.15);
    color: #b53f32;
}

.status-badge--waiting_customer {
    background: rgba(155, 93, 229, 0.12);
    color: #6e43a4;
}

.status-badge--resolved,
.status-badge--closed {
    background: rgba(47, 163, 125, 0.14);
    color: #1f7a5c;
}

.kplus-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 999px;
}

.priority-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.36rem 0.62rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 800;
    white-space: nowrap;
}

.priority-badge--base {
    background: rgba(107, 102, 95, 0.12);
    color: var(--muted);
}

.priority-badge--kplus-1 {
    background: rgba(245, 183, 0, 0.16);
    color: #8a6400;
}

.priority-badge--kplus-2 {
    background: rgba(255, 130, 42, 0.22);
    color: #a74500;
    box-shadow: inset 0 0 0 1px rgba(255, 130, 42, 0.18);
}

.priority-badge--kplus-3 {
    background: #c92f25;
    color: #fff;
    box-shadow: 0 8px 18px rgba(201, 47, 37, 0.24);
}

.priority-stack {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.page-view {
    display: none;
}

.page-view.is-active {
    display: block;
}

.refresh-toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 40;
    padding: 0.9rem 1rem 0.9rem 2.6rem;
    background: rgba(31, 29, 26, 0.94);
    border-radius: 16px;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 18px 48px rgba(31, 29, 26, 0.22);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.refresh-toast::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 1rem;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 999px;
    transform: translateY(-50%);
    animation: spin 0.8s linear infinite;
}

.refresh-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.panel-loading.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(2px);
}

.panel-loading.is-loading::before {
    content: '';
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 2;
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 106, 99, 0.2);
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.panel-loading.is-loading-soft::after {
    background: rgba(255, 255, 255, 0.36);
}

.ticket-detail-panel {
    position: fixed;
    top: 18px;
    right: 18px;
    bottom: 18px;
    z-index: 1095;
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: min(520px, calc(100vw - 36px));
    padding: 24px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: 0 28px 80px rgba(62, 35, 22, 0.18);
    transform: translateX(calc(100% + 24px));
    transition: transform 0.24s ease;
    backdrop-filter: blur(18px);
}

.ticket-detail-panel.is-open {
    transform: translateX(0);
}

.ticket-detail-panel.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.62);
    border-radius: inherit;
}

.ticket-detail-panel.is-loading::before {
    content: '';
    position: absolute;
    top: 22px;
    right: 62px;
    z-index: 2;
    width: 26px;
    height: 26px;
    border: 3px solid rgba(255, 106, 99, 0.2);
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.ticket-detail-header {
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.ticket-detail-header h2 {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.ticket-detail-body,
.ticket-detail-notes {
    display: grid;
    gap: 12px;
    overflow: auto;
}

.ticket-detail-body {
    padding-right: 4px;
}

.ticket-detail-section-title {
    margin: 4px 0 -4px;
    font-size: 1rem;
    font-weight: 800;
}

.detail-item,
.note-card {
    padding: 14px;
    background: rgba(251, 247, 242, 0.92);
    border-radius: 16px;
}

.detail-item span,
.note-card span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

.detail-item p,
.note-card p {
    margin: 0;
    color: var(--ink);
    line-height: 1.45;
}

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

@media (max-width: 1400px) {
    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .content-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .dashboard-column-width {
        width: calc((100% - 16px) / 2);
    }

    .side-panel {
        grid-column: 1 / -1;
    }
}

@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 991px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: static;
        width: 100%;
        min-height: auto;
    }

    .page-header {
        flex-direction: column;
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

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

    .dashboard-column-width {
        width: 100%;
    }
}

@media (max-width: 767px) {
    .content-area {
        padding: 22px 16px 28px;
    }

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