:root {
    --primary: #190019;
    --primary-dark: #2B124C;
    --secondary: #522B5B;
    --accent: #854F6C;
    --muted: #C1A9D9;
    --card: #f2e9f7; /* меньше бежевого, чуть фиолетовый */
    --text: #190019;
    --bg: linear-gradient(180deg, #190019 0%, #2B124C 40%, #522B5B 65%, #854F6C 82%, #C1A9D9 100%);
    --border: rgba(25, 0, 25, 0.12);
    --danger: #c53030;
    --success: #2f855a;
    --shadow: 0 12px 28px rgba(25, 0, 25, 0.25);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-header {
    background: rgba(25,0,25,0.9);
    color: #f2e9f7;
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 24px rgba(1,4,64,0.2);
}
.brand {
    font-size: 20px;
    font-weight: 700;
    color: #f2e9f7;
    text-decoration: none;
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.brand-logo {
    width: 28px;
    height: 28px;
    display: inline-block;
}
.nav-links a {
    color: #f2e9f7;
    text-decoration: none;
    margin-left: 10px;
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid transparent;
    transition: background .15s ease, transform .1s ease, border .15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.nav-links a:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.18); }
.nav-links a.active {
    background: #fff;
    color: var(--primary);
    border-color: rgba(1,28,64,0.25);
    box-shadow: 0 6px 12px rgba(1,28,64,0.2);
    transform: translateY(-1px);
}

.app-main { padding: 40px; min-height: 100vh; }
.container { padding: 0; }
.page-card { max-width: 1200px; margin: 0 auto; }
.table-card { padding: 16px; border-radius: 18px; box-shadow: var(--shadow); background: rgba(255,255,255,0.9); }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.card.narrow { max-width: 520px; margin: 0 auto; }
.center-card { max-width: 640px; margin: 40px auto; text-align: center; }
.icon { font-size: 48px; margin-bottom: 10px; color: var(--primary); }
h2 { margin-top: 0; }
p { color: var(--muted); }

.table-card { overflow: hidden; }
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: 14px;
    background: rgba(255,255,255,0.9);
    box-shadow: 0 6px 16px rgba(25,0,25,0.18);
}
.table-wrapper.expanded table { min-width: 1200px; }
table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255,255,255,0.82);
    border-radius: 14px;
    table-layout: fixed;
    min-width: 900px;
}
th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid rgba(25,0,25,0.1);
    font-size: 14px;
}
th { background: var(--secondary); color: #fff; }
th, td { position: relative; }
.resizable { position: relative; }
.col-resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
}
.resizing {
    cursor: col-resize !important;
    user-select: none;
}
tr:hover { background: rgba(133,79,108,0.12); }

.inner-table {
    width: 100%;
    border-collapse: collapse;
}
.inner-table th, .inner-table td {
    padding: 8px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.inner-table th {
    background: rgba(0,0,0,0.04);
    color: var(--text);
}
.group-row td { background: rgba(255,255,255,0.95); }
.details-row td { background: rgba(0,0,0,0.02); }
.cell-text {
    word-break: break-word;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 420px;
}
.cell-text.expanded {
    white-space: normal;
    text-overflow: initial;
    max-width: 100%;
}
.cell-user, .cell-client { white-space: nowrap; }

.caret-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 6px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: var(--text);
    transition: background .15s ease, transform .1s ease;
}
.caret-btn:hover { background: rgba(0,0,0,0.05); transform: translateY(-1px); }

.actions {
    display: flex;
    gap: 6px;
    align-items: center;
}
.btn-icon {
    border: none;
    border-radius: 999px;
    padding: 6px 10px;
    cursor: pointer;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    transition: transform .1s ease, box-shadow .1s ease;
}
.btn-icon.edit { background: linear-gradient(120deg, var(--primary), var(--secondary)); }
.btn-icon.delete { background: #b22222; }
.btn-icon:hover { transform: translateY(-1px); box-shadow: 0 6px 12px rgba(0,0,0,0.15); }

.deleted-row td {
    text-decoration: line-through;
    opacity: 0.75;
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 8px;
}
.btn-ghost {
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.85);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s ease, transform .1s ease;
}
.btn-ghost:hover { background: rgba(0,0,0,0.05); transform: translateY(-1px); }

.skeleton {
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, rgba(0,0,0,0.05) 25%, rgba(0,0,0,0.08) 50%, rgba(0,0,0,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
    border-radius: 6px;
    height: 16px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.btn {
    padding: 9px 14px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform .1s ease, box-shadow .1s ease, background .2s ease;
}
.btn-primary { background: linear-gradient(90deg, var(--primary), var(--secondary)); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(25,0,25,0.25); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(58,52,91,0.5);
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-content {
    background: #F3C8DD;
    border-radius: 14px;
    width: 100%;
    max-width: 1000px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 32px rgba(58,52,91,0.25);
}
.modal-header { padding: 12px 16px; background: #71557A; color: #fff; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; overflow-y: auto; }
.close { cursor: pointer; font-size: 20px; }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(14,26,76,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1200;
}
.overlay-content {
    background: rgba(255,255,255,0.95);
    border-radius: 14px;
    padding: 18px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 16px 32px rgba(14,26,76,0.25);
}

.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 600; color: #3A345B; }
.form-group.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.form-control, textarea.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f7eaf2;
    color: var(--text);
}
textarea.form-control { min-height: 90px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; border-radius: 14px; }

.toggle {
    position: relative; width: 44px; height: 22px; display: inline-block;
}
.toggle input { display: none; }
.toggle span {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--danger); border-radius: 22px; transition: .2s;
}
.toggle span:before {
    position: absolute; content: ""; height: 18px; width: 18px;
    left: 2px; bottom: 2px; background: white; border-radius: 50%; transition: .2s;
}
.toggle input:checked + span { background: #198754; }
.toggle input:checked + span:before { transform: translateX(22px); }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
    background: #f7eaf2;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.note { font-size: 12px; color: var(--muted); text-align: center; }
.status { font-weight: 600; text-align: center; margin-top: 10px; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

.buttons-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 6px;
}
.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr 42px;
    gap: 8px;
    align-items: center;
}
.button-row input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f7eaf2;
    color: var(--text);
    font-size: 13px;
}
.btn-square {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
}
.btn-danger { background: var(--danger); color: #fff; }

.status-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
    vertical-align: middle;
    margin-right: 6px;
}
.status-dot.pending { background: #f7c948; }    /* in progress */
.status-dot.sent { background: #16a34a; }       /* sent */
.status-dot.deleting { background: #f97316; }   /* deleting */
.status-dot.deleted { background: #dc2626; }    /* deleted */
.status-text { font-size: 12px; color: #3A345B; vertical-align: middle; }

.status-emoji {
    font-size: 18px;
    line-height: 1;
    display: inline-block;
    cursor: default;
}

.center-label {
    display: block;
    text-align: center;
}

.round-checkbox {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    transition: all .15s ease;
}
.round-checkbox:checked {
    background: var(--primary);
    box-shadow: inset 0 0 0 3px #fff;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
    display: inline-block;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd2d9;
    border-radius: 26px;
    transition: .2s;
}
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: .2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(120deg, var(--primary), var(--secondary));
}
.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Responsive */
@media (max-width: 1024px) {
    .app-main { padding: 20px; }
    .modal-body { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .nav-links {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .nav-links a {
        margin-left: 0;
    }
    .card,
    .table-card {
        padding: 14px;
    }
    .table-wrapper { margin: 0 -6px; padding: 0 6px; }
    table { min-width: 720px; }
    .form-group { margin-bottom: 10px; }
    .form-control, textarea.form-control {
        width: 100%;
    }
    .button-row {
        grid-template-columns: 1fr;
    }
    .btn { width: 100%; justify-content: center; }
    .modal-content { max-width: 100%; }
}

@media (max-width: 480px) {
    .app-main { padding: 14px; }
    h2 { font-size: 20px; }
    th, td { padding: 10px; font-size: 13px; }
    .nav-links a { font-size: 13px; padding: 8px 10px; }
    .modal-body { padding: 12px; }
    .status-emoji, .status-dot { margin-right: 4px; }
}
