:root {
    color-scheme: dark;
}

body.dark-app {
    background-color: #0a0f16;
    color: #e2e8f0;
}

.dark-card {
    background-color: #121820;
    border: 1px solid rgba(51, 65, 85, 0.55);
    border-radius: 0.75rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.dark-card-inner {
    background-color: #0d1219;
    border: 1px solid rgba(51, 65, 85, 0.45);
    border-radius: 0.625rem;
}

.dark-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #94a3b8;
    margin-bottom: 0.375rem;
}

.dark-input,
.dark-select {
    width: 100%;
    min-height: 44px;
    padding: 0.625rem 0.875rem;
    background-color: #0a0e14;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    color: #f8fafc;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.dark-input::placeholder {
    color: #64748b;
}

.dark-input:focus,
.dark-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.dark-select option {
    background-color: #121820;
    color: #f8fafc;
}

.dark-checkbox {
    width: 1rem;
    height: 1rem;
    border-radius: 0.25rem;
    border-color: #475569;
    background-color: #0a0e14;
    color: #3b82f6;
}

.dark-checkbox:focus {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.625rem 1rem;
    background-color: #2563eb;
    border: 1px solid #2563eb;
    border-radius: 0.5rem;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.15s;
}

.btn-primary:hover {
    background-color: #3b82f6;
}

.btn-primary:active {
    background-color: #1d4ed8;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.625rem 1rem;
    background-color: #1a2230;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    color: #cbd5e1;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
    background-color: #1e293b;
    border-color: #475569;
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 1rem;
}

.section-subtitle {
    font-size: 0.875rem;
    color: #64748b;
    margin-top: -0.5rem;
    margin-bottom: 1rem;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    background-color: #1a2230;
    border: 1px solid #334155;
    color: #cbd5e1;
}

.meta-chip-accent {
    background-color: rgba(37, 99, 235, 0.15);
    border-color: rgba(59, 130, 246, 0.35);
    color: #93c5fd;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background-color: rgba(37, 99, 235, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #93c5fd;
    transition: background-color 0.15s;
}

.filter-chip:hover {
    background-color: rgba(37, 99, 246, 0.25);
}

.table-scroll {
    -webkit-overflow-scrolling: touch;
}

.table-scroll::-webkit-scrollbar {
    height: 6px;
}

.table-scroll::-webkit-scrollbar-track {
    background: #0a0e14;
    border-radius: 4px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

.dark-table thead {
    background-color: #0d1219;
}

.dark-table th {
    color: #94a3b8;
    border-bottom: 1px solid #1e293b;
}

.dark-table tbody tr {
    border-bottom: 1px solid rgba(30, 41, 59, 0.6);
}

.dark-table tbody tr:hover {
    background-color: rgba(30, 41, 59, 0.35);
}

.dark-table td {
    color: #cbd5e1;
}

/* Планшет — горизонтальный скролл */
@media (min-width: 768px) and (max-width: 1023px) {
    .dark-table-fit {
        min-width: 900px;
    }
}

/* Компьютер — таблица на всю ширину без горизонтального скрола */
@media (min-width: 1024px) {
    .table-scroll {
        overflow-x: hidden;
    }

    .dark-table-fit {
        table-layout: fixed;
        width: 100%;
        font-size: 0.75rem;
    }

    .dark-table-fit th,
    .dark-table-fit td {
        padding: 0.375rem 0.375rem;
        vertical-align: top;
        overflow: hidden;
        word-wrap: break-word;
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .dark-table-fit col.col-phones,
    .dark-table-fit col.col-email,
    .dark-table-fit col.col-website {
        display: none;
    }

    .dark-table-fit .col-num { width: 3%; }
    .dark-table-fit .col-name { width: 16%; }
    .dark-table-fit .col-city { width: 9%; }
    .dark-table-fit .col-inn { width: 8%; }
    .dark-table-fit .col-status { width: 10%; }
    .dark-table-fit .col-director { width: 12%; }
    .dark-table-fit .col-okved { width: 6%; }
    .dark-table-fit .col-comment { width: 28%; }
    .dark-table-fit .col-link { width: 8%; }

    td.contact-cell,
    td.comment-cell {
        min-width: 0;
        max-width: none;
    }

    .comment-field {
        min-width: 0;
        width: 100%;
        min-height: 3rem;
        max-height: 5.5rem;
        font-size: 0.6875rem;
        padding: 0.375rem 0.5rem;
        resize: none;
    }

    .comment-color-btn {
        width: 1rem;
        height: 1rem;
    }

    .comment-wrap {
        gap: 0.25rem;
    }

    .contact-line {
        font-size: 0.6875rem;
        line-height: 1.35;
    }

    .dark-table-fit .cell-name {
        font-size: 0.75rem;
        line-height: 1.35;
    }

    .dark-table-fit .cell-link {
        font-size: 0.6875rem;
    }
}

@media (min-width: 1280px) {
    .dark-table-fit col.col-phones,
    .dark-table-fit col.col-email {
        display: table-column;
    }

    .dark-table-fit .col-name { width: 12%; }
    .dark-table-fit .col-director { width: 9%; }
    .dark-table-fit .col-phones { width: 11%; }
    .dark-table-fit .col-email { width: 10%; }
    .dark-table-fit .col-comment { width: 17%; }
    .dark-table-fit .col-link { width: 5.5%; }
}

@media (min-width: 1536px) {
    .dark-table-fit col.col-website {
        display: table-column;
    }

    .dark-table-fit {
        font-size: 0.8125rem;
    }

    .dark-table-fit .col-website { width: 9%; }
    .dark-table-fit .col-comment { width: 15%; }

    .comment-field {
        min-height: 3.25rem;
        max-height: 6rem;
        font-size: 0.75rem;
    }
}

.safe-area {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
}

.contact-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.contact-line {
    display: block;
    line-height: 1.45;
    user-select: all;
    -webkit-user-select: all;
    cursor: text;
}

.contact-line:hover {
    color: #7dd3fc;
}

td.contact-cell {
    vertical-align: top;
    min-width: 11rem;
    max-width: 22rem;
}

.comment-field {
    width: 100%;
    min-width: 200px;
    min-height: 72px;
    padding: 0.5rem 0.625rem;
    background-color: #0a0e14;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    color: #e2e8f0;
    font-size: 0.75rem;
    line-height: 1.45;
    resize: vertical;
    user-select: text;
    -webkit-user-select: text;
}

.comment-field:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.comment-field.is-saving {
    border-color: #d97706;
}

.comment-field.is-saved {
    border-color: #059669;
}

.comment-field::placeholder {
    color: #64748b;
}

td.comment-cell {
    vertical-align: top;
    min-width: 220px;
    max-width: 360px;
}

.comment-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.comment-color-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
}

.comment-color-btn {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.comment-color-btn:hover {
    transform: scale(1.1);
}

.comment-color-btn.is-active {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #3b82f6;
}

.comment-color-btn[data-color="default"] {
    background: linear-gradient(135deg, #334155 50%, #0a0e14 50%);
    border-color: #475569;
}

.comment-color-btn[data-color="red"] { background-color: #ef4444; }
.comment-color-btn[data-color="yellow"] { background-color: #eab308; }
.comment-color-btn[data-color="green"] { background-color: #22c55e; }
.comment-color-btn[data-color="blue"] { background-color: #3b82f6; }

.comment-field.comment-color-default,
.comment-field.comment-color- {
    background-color: #0a0e14;
    border-color: #334155;
}

.comment-field.comment-color-red {
    background-color: rgba(127, 29, 29, 0.35);
    border-color: #ef4444;
}

.comment-field.comment-color-yellow {
    background-color: rgba(113, 63, 18, 0.35);
    border-color: #eab308;
}

.comment-field.comment-color-green {
    background-color: rgba(20, 83, 45, 0.35);
    border-color: #22c55e;
}

.comment-field.comment-color-blue {
    background-color: rgba(30, 58, 138, 0.35);
    border-color: #3b82f6;
}

.red-alerts-banner {
    position: sticky;
    top: 3.5rem;
    z-index: 25;
    background: linear-gradient(180deg, rgba(69, 10, 10, 0.98), rgba(45, 8, 8, 0.95));
    border-bottom: 1px solid rgba(239, 68, 68, 0.45);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (min-width: 640px) {
    .red-alerts-banner {
        top: 4rem;
    }
}

.red-alerts-banner-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.red-alerts-icon {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    background: #ef4444;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

.red-alerts-title {
    color: #fecaca;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
}

.red-alerts-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 120px;
    overflow-y: auto;
}

.red-alerts-list li {
    color: #fee2e2;
    font-size: 0.8125rem;
    line-height: 1.45;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(239, 68, 68, 0.15);
}

.red-alerts-list li:last-child {
    border-bottom: 0;
}

.red-alerts-list strong {
    color: #fff;
}

.red-alerts-close {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(127, 29, 29, 0.5);
    color: #fecaca;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s;
}

.red-alerts-close:hover {
    background: rgba(153, 27, 27, 0.7);
    color: #fff;
}

/* AI-помощник */
/* Сворачиваемые секции */
.section-toggle {
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: background-color 0.15s;
}

.section-toggle:hover {
    background: rgba(30, 41, 59, 0.35);
}

.section-toggle-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.625rem;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-toggle-icon-ai {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
}

.section-toggle-icon-search {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
}

.section-toggle-icon-filter {
    background: linear-gradient(135deg, #6366f1, #2563eb);
}

.ai-assistant-toggle {
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: background-color 0.15s;
}

.ai-assistant-toggle:hover {
    background: rgba(30, 41, 59, 0.35);
}

.ai-assistant-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.625rem;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-subtitle {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #cbd5e1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ai-wish-card {
    background: #0d1219;
    border: 1px solid rgba(51, 65, 85, 0.55);
    border-radius: 0.625rem;
    padding: 0.875rem 1rem;
    min-height: 3.5rem;
    position: relative;
}

.ai-wish-text {
    color: #e2e8f0;
    font-size: 0.9375rem;
    line-height: 1.55;
    margin: 0;
}

.ai-wish-meta {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: #64748b;
}

.ai-wish-loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(13, 18, 25, 0.85);
    border-radius: 0.625rem;
    color: #94a3b8;
    font-size: 0.875rem;
}

.ai-wish-loading.is-visible {
    display: flex;
}

.ai-btn-ghost {
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
    border: 1px solid #334155;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.ai-btn-ghost:hover:not(:disabled) {
    color: #e2e8f0;
    border-color: #475569;
}

.ai-btn-ghost:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-notice {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    background: rgba(30, 58, 138, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #bfdbfe;
    font-size: 0.875rem;
    line-height: 1.5;
}

.ai-link {
    color: #60a5fa;
    text-decoration: underline;
}

.ai-code {
    font-family: ui-monospace, monospace;
    font-size: 0.8125rem;
    background: rgba(15, 23, 42, 0.6);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

.ai-chat-messages {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.ai-msg {
    padding: 0.625rem 0.75rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    line-height: 1.45;
}

.ai-msg-user {
    background: rgba(37, 99, 235, 0.18);
    border: 1px solid rgba(59, 130, 246, 0.25);
    align-self: flex-end;
    max-width: 92%;
}

.ai-msg-assistant {
    background: #0d1219;
    border: 1px solid rgba(51, 65, 85, 0.55);
    align-self: flex-start;
    max-width: 92%;
}

.ai-msg-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.ai-msg-text {
    color: #e2e8f0;
    word-break: break-word;
}

.ai-chat-form {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

@media (min-width: 640px) {
    .ai-chat-form {
        flex-direction: row;
        align-items: flex-end;
    }
}

.ai-chat-input {
    flex: 1;
    min-height: 44px;
    resize: vertical;
}

.ai-chat-actions {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    flex-shrink: 0;
}

.ai-chat-send,
.ai-chat-clear {
    min-height: 44px;
    white-space: nowrap;
}

.rotate-180 {
    transform: rotate(180deg);
}

.pagination-bar.is-loading {
    opacity: 0.65;
    pointer-events: none;
}
