/**
 * CRM Техподдержки - Основные стили
 * Поддержка светлой и тёмной тем
 */

/* CSS Variables - Light Theme (default) */
:root {
    /* Background colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --bg-hover: #f9fafb;

    /* Text colors */
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-inverse: #ffffff;

    /* Accent colors */
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-secondary: #60a5fa;

    /* Status colors */
    --color-success: #10b981;
    --color-success-bg: #d1fae5;
    --color-warning: #f59e0b;
    --color-warning-bg: #fef3c7;
    --color-error: #ef4444;
    --color-error-bg: #fee2e2;
    --color-info: #3b82f6;
    --color-info-bg: #dbeafe;

    /* Priority colors */
    --priority-low: #10b981;
    --priority-normal: #3b82f6;
    --priority-high: #f59e0b;
    --priority-urgent: #ef4444;

    /* Status colors */
    --status-new: #8b5cf6;
    --status-open: #3b82f6;
    --status-pending: #f59e0b;
    --status-waiting: #6b7280;
    --status-resolved: #10b981;
    --status-closed: #374151;

    /* Borders */
    --border-color: #e5e7eb;
    --border-focus: #3b82f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;

    /* Border radius */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --bg-hover: #374151;

    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-tertiary: #6b7280;
    --text-inverse: #1f2937;

    --accent-primary: #60a5fa;
    --accent-primary-hover: #3b82f6;
    --accent-secondary: #93c5fd;

    --color-success-bg: #064e3b;
    --color-warning-bg: #78350f;
    --color-error-bg: #7f1d1d;
    --color-info-bg: #1e3a8a;

    --border-color: #374151;
    --border-focus: #60a5fa;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

/* System theme detection */
@media (prefers-color-scheme: dark) {
    [data-theme="system"] {
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --bg-tertiary: #374151;
        --bg-hover: #374151;
        --text-primary: #f3f4f6;
        --text-secondary: #9ca3af;
        --text-tertiary: #6b7280;
        --text-inverse: #1f2937;
        --accent-primary: #60a5fa;
        --accent-primary-hover: #3b82f6;
        --accent-secondary: #93c5fd;
        --color-success-bg: #064e3b;
        --color-warning-bg: #78350f;
        --color-error-bg: #7f1d1d;
        --color-info-bg: #1e3a8a;
        --border-color: #374151;
        --border-focus: #60a5fa;
    }
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-primary-hover);
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    gap: 0.75rem;
}

.sidebar-nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-nav-item.active {
    background-color: var(--accent-primary);
    color: var(--text-inverse);
}

.sidebar-nav-item .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.header {
    height: var(--header-height);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-content {
    flex: 1;
    padding: 1.5rem;
}

/* Cards */
.card {
    background-color: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background-color: var(--accent-primary);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background-color: var(--accent-primary-hover);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-success {
    background-color: var(--color-success);
    color: white;
}

.btn-danger {
    background-color: var(--color-error);
    color: white;
}

.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
}

.badge-priority-low { background-color: #d1fae5; color: #065f46; }
.badge-priority-normal { background-color: #dbeafe; color: #1e40af; }
.badge-priority-high { background-color: #fef3c7; color: #92400e; }
.badge-priority-urgent { background-color: #fee2e2; color: #991b1b; }

.badge-status-new { background-color: #ede9fe; color: #5b21b6; }
.badge-status-open { background-color: #dbeafe; color: #1e40af; }
.badge-status-pending { background-color: #fef3c7; color: #92400e; }
.badge-status-waiting { background-color: #f3f4f6; color: #374151; }
.badge-status-resolved { background-color: #d1fae5; color: #065f46; }
.badge-status-closed { background-color: #e5e7eb; color: #1f2937; }

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
}

.table tbody tr:hover {
    background-color: var(--bg-hover);
}

/* Ticket list */
.ticket-row {
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.ticket-row:hover {
    background-color: var(--bg-hover);
}

.ticket-number {
    font-family: monospace;
    font-weight: 600;
    color: var(--accent-primary);
}

.ticket-subject {
    font-weight: 500;
    color: var(--text-primary);
}

.ticket-subject-truncate {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Messages */
.message-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    gap: 0.75rem;
}

.message-user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    background-color: var(--bg-secondary);
}

.message-user .message-bubble {
    background-color: var(--accent-primary);
    color: var(--text-inverse);
}

.message-internal .message-bubble {
    background-color: var(--color-warning-bg);
    border: 1px dashed var(--color-warning);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

/* Utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

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

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }
}
