/*
 * osTicket Modern Theme v2
 * Полная переработка с чистого листа
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Light Theme */
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-hover: #f8fafc;
    --bg-input: #ffffff;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border-light: #e2e8f0;
    --border-medium: #cbd5e1;
    
    --primary: #0ea5e9;
    --primary-hover: #0284c7;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    
    --radius: 8px;
    --radius-lg: 12px;
    
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --bg-input: #1e293b;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --border-light: #334155;
    --border-medium: #475569;
    
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --info: #60a5fa;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

/* ============================================
   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: var(--font-main);
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-body);
    min-height: 100vh;
}

/* ============================================
   LAYOUT
   ============================================ */
#container {
    max-width: 1400px;
    margin: 0 auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#content {
    flex: 1;
    padding: 2rem;
    width: 100%;
}

/* ============================================
   HEADER
   ============================================ */
#header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    padding: 0 2rem;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

#logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
}

#logo img {
    max-height: 40px;
    width: auto;
    filter: invert(0%);
    transition: filter 0.3s ease;
}

[data-theme="dark"] #logo img {
    filter: invert(100%);
}

#header .pull-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

#header p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#header a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

#header a:hover {
    text-decoration: underline;
}

/* Theme Toggle */
.theme-toggle {
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    padding: 0;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
[data-theme="dark"] .theme-toggle .moon-icon { display: none; }

/* ============================================
   NAVIGATION
   ============================================ */
#nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    padding: 0 2rem;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
}

#nav ul {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
}

#nav li a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s;
}

#nav li a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#nav li a.active {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
}

#nav li a i {
    font-size: 0.875rem;
}

/* ============================================
   FOOTER
   ============================================ */
#footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/*#footer p {*/
/*    margin-bottom: 1rem;*/
/*}*/
.row {
    display: flex;
    flex-direction: row;
}

@media (max-width: 768px) {
    .row {
        flex-direction: column;
    }
}

.span8 {
    width: 100%;
}

#poweredBy {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-hover);
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
}

#poweredBy:hover {
    background: var(--bg-hover);
    color: var(--primary);
    text-decoration: none;
}

/* ============================================
   ALERTS
   ============================================ */
#msg_notice, #msg_warning, #msg_error, #msg_info,
.notice_bar, .warning_bar, .error_bar, .warning-banner {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

#msg_notice i, #msg_warning i, #msg_error i, #msg_info i {
    font-size: 1.5rem;
    margin-top: 0.125rem;
}

#msg_notice, .notice_bar {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

#msg_warning, .warning_bar, .warning-banner {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

#msg_error, .error_bar {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

#msg_info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

[data-theme="dark"] #msg_notice, [data-theme="dark"] .notice_bar {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

[data-theme="dark"] #msg_warning, [data-theme="dark"] .warning_bar, [data-theme="dark"] .warning-banner {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

[data-theme="dark"] #msg_error, [data-theme="dark"] .error_bar {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

[data-theme="dark"] #msg_info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

/* ============================================
   BUTTONS
   ============================================ */
.button,
input[type="submit"],
input[type="button"],
input[type="reset"],
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: var(--font-main);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    min-height: 40px;
}

.button,
input[type="submit"],
input[type="button"] {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    box-shadow: var(--shadow-sm);
}

.button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: white;
}

.green.button {
    background: linear-gradient(135deg, var(--success), #059669);
}

.blue.button {
    background: linear-gradient(135deg, var(--info), var(--primary));
}

input[type="reset"],
.button.secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    min-height: 44px;
}

input[type="reset"]:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.action-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    text-decoration: none;
    transition: all 0.2s;
}

.action-button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

/* ============================================
   DYNAMIC FORMS
   ============================================ */
#dynamic-form table,
#dynamic-form tr,
#dynamic-form td {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
}

#dynamic-form tr {
    margin-bottom: 1.5rem;
}

#dynamic-form td {
    padding: 0 !important;
}

#dynamic-form .form-header {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 1.5rem 0 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary);
}

#dynamic-form .form-header h3 {
    margin: 0 0 0.5rem;
    font-size: 1.125rem;
}

#dynamic-form .form-header div {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

#dynamic-form hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 2rem 0;
}

/* ============================================
   FORMS
   ============================================ */
form {
    margin: 0;
}

/* Fix legacy form tables */
#ticketForm > table,
#ticketForm table {
    width: 100%;
}

#ticketForm > table > tbody,
#ticketForm > table > tbody > tr,
#ticketForm table > tbody,
#ticketForm table > tbody > tr {
    display: contents;
}

#ticketForm > table > tbody > tr > td,
#ticketForm table > tbody > tr > td {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    margin-bottom: 1.5rem;
}

#ticketForm td[colspan="2"] {
    margin-bottom: 1.5rem;
}

#ticketForm td:first-child {
    margin-bottom: 0.5rem;
}

#ticketForm td:first-child label {
    margin-bottom: 0;
}

#ticketForm input:not([type="checkbox"]):not([type="radio"]),
#ticketForm select,
#ticketForm textarea {
    width: 100%;
    max-width: 100%;
}

#ticketForm textarea {
    min-height: 150px;
}

#ticketForm hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 2rem 0;
    grid-column: 1 / -1;
}

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

label.required::after {
    content: " *";
    color: var(--danger);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    font-family: var(--font-main);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    transition: all 0.2s;
    outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

textarea {
    resize: vertical;
    min-height: 150px;
    line-height: 1.6;
}

input[type="file"] {
    padding: 0.5rem 0;
    border: none;
    background: transparent;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
    accent-color: var(--primary);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-control-static {
    padding: 0.75rem 1rem;
    background: var(--bg-hover);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-weight: 500;
}

.form-actions,
p.buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    padding: 1.5rem 0;
    margin-top: 1.5rem;
    border-top: 1px solid var(--border-light);
}

.form-actions input,
p.buttons input {
    min-width: 120px;
}

/* Captcha */
.captchaRow {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.captchaRow td {
    display: flex !important;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.captcha img {
    border-radius: var(--radius);
}

#captcha {
    width: 150px !important;
}

/* ============================================
   HEADINGS
   ============================================ */
h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

h1 small {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.875rem;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

/* ============================================
   LANDING PAGE
   ============================================ */
.landing-hero {
    text-align: center;
    padding: 3rem 2rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.landing-hero h1 {
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.landing-hero p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    margin-bottom: 2rem;
}

.search-form form {
    display: flex;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.search-form .search {
    flex: 1;
    padding: 1rem 1.25rem;
    font-size: 1rem;
}

.search-form button {
    padding: 1rem 2rem;
    white-space: nowrap;
}

.action-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.action-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
}

.action-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    text-decoration: none;
}

.action-card-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    border-radius: var(--radius-lg);
    color: white;
    font-size: 1.5rem;
}

.action-card h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.action-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.featured-articles {
    margin-top: 3rem;
}

.featured-articles h1 {
    justify-content: center;
    margin-bottom: 1.5rem;
}

.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.article-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text-primary);
    display: block;
}

.article-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    transform: translateY(-2px);
    text-decoration: none;
    color: var(--text-primary);
}

.article-card-icon {
    color: var(--primary);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.article-card h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.article-teaser {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   TICKET TABLE
   ============================================ */
#ticketTable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin: 1.5rem 0;
}

#ticketTable caption {
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-light);
}

#ticketTable thead {
    background: var(--bg-hover);
}

#ticketTable th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

#ticketTable th a {
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#ticketTable th a:hover {
    color: var(--primary);
}

#ticketTable tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background 0.2s;
}

#ticketTable tbody tr:hover {
    background: var(--bg-hover);
}

#ticketTable tbody tr:last-child {
    border-bottom: none;
}

#ticketTable td {
    padding: 1rem 1.5rem;
    color: var(--text-primary);
    vertical-align: middle;
}

#ticketTable td a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

#ticketTable td a:hover {
    text-decoration: underline;
}

.ticket-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 500;
}

.ticket-status-open {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.ticket-status-closed {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

/* Ticket source icons */
.Icon {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.Icon::before {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 1rem;
    color: var(--primary);
}

.Icon.webTicket::before { content: "\f0ac"; }
.Icon.emailTicket::before { content: "\f0e0"; }
.Icon.phoneTicket::before { content: "\f095"; }
.Icon.otherTicket::before,
.Icon.apiTicket::before { content: "\f121"; }

/* Responsive table */
@media (max-width: 768px) {
    #ticketTable,
    #ticketTable thead,
    #ticketTable tbody,
    #ticketTable th,
    #ticketTable td,
    #ticketTable tr {
        display: block;
    }
    
    #ticketTable thead {
        position: absolute;
        left: -9999px;
    }
    
    #ticketTable tbody tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-light);
        border-radius: var(--radius);
        padding: 1rem;
    }
    
    #ticketTable td {
        padding: 0.5rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border-light);
    }
    
    #ticketTable td:last-child {
        border-bottom: none;
    }
    
    #ticketTable td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.8125rem;
        text-transform: uppercase;
    }
}

/* ============================================
   TICKET VIEW
   ============================================ */
#ticketInfo {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

#ticketInfo .ticket-header {
    padding: 1.5rem;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

#ticketInfo .ticket-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

#ticketInfo .ticket-title h1 {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    font-size: 1.25rem;
    justify-content: flex-start;
}

#ticketInfo .ticket-title h1 small {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.875rem;
    margin-left: 0.75rem;
}

#ticketInfo .ticket-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ticket-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
}

.meta-card {
    background: var(--bg-hover);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border-light);
}

.meta-header {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.meta-header i {
    color: var(--primary);
}

.meta-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
}

.meta-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.meta-label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.meta-value {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
}

@media (max-width: 768px) {
    .meta-row {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .meta-value {
        text-align: left;
    }
}

.custom-data {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.custom-data .headline {
    font-weight: 600;
    color: var(--text-primary);
    padding: 1rem 1.5rem !important;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-light);
}

.custom-data tr {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

@media (max-width: 768px) {
    .custom-data tr {
        grid-template-columns: 1fr;
    }
}

.custom-data th {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.custom-data td {
    color: var(--text-primary);
}

/* Thread / Ticket entries */
.thread-body {
    background: transparent;
    box-shadow: none;
}

#ticketThread {
    margin-top: 2rem;
}

#ticketThread > * {
    margin-top: 0;
    margin-bottom: 0;
}

#ticketThread > *:not(:last-child) {
    margin-bottom: 1.5rem;
}

.thread-entry {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    position: relative;
}

.thread-entry.avatar {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.thread-entry .avatar {
    position: absolute;
    /*top: 1.5rem;*/
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.thread-entry .avatar.pull-left {
    left: -2.5rem;
}

.thread-entry .avatar.pull-right {
    right: -2.5rem;
}

.thread-entry .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thread-entry .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.thread-entry .header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.thread-entry .header-left b {
    white-space: nowrap;
}

.thread-entry .header-left time {
    color: var(--text-muted);
    font-size: 0.875rem;
    white-space: nowrap;
}

.thread-entry .header-left .title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
    width: 100%;
}

.thread-entry .header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .thread-entry .header {
        flex-wrap: wrap;
    }
    
    .thread-entry .header-right {
        width: 100%;
        justify-content: flex-end;
    }
}

.thread-entry .thread-body {
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 0.9375rem;
}

.thread-entry .thread-body > div:first-child {
    background: transparent !important;
    padding: 0;
}

.thread-entry .attachments {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.thread-entry .attachment-info {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-hover);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.thread-entry .attachment-info a {
    color: var(--primary);
    text-decoration: none;
}

.thread-entry .attachment-info a:hover {
    text-decoration: underline;
}

.thread-entry .attachment-info .filesize {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* Thread events (status changes, assignments, etc.) */
.thread-event {
    background: var(--bg-hover);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    border-left: 3px solid var(--border-medium);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.thread-event.action {
    background: linear-gradient(135deg, rgba(14, 165, 239, 0.08), rgba(99, 102, 241, 0.08));
    border-left-color: var(--primary);
}

.thread-event.state {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(5, 150, 105, 0.08));
    border-left-color: var(--success);
}

.thread-event.info {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(37, 99, 235, 0.08));
    border-left-color: var(--info);
}

.thread-event .avatar {
    position: static;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.thread-event .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.thread-event .faded {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
}

.thread-event .faded b {
    color: var(--text-primary);
    font-weight: 600;
}

.thread-event .description {
    display: block;
    margin-top: 0.25rem;
}

/* Reply form */
#reply {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    margin-top: 2rem;
}

#reply h2 {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

#reply .buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-light);
}

.refresh-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--success);
    text-decoration: none;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.refresh-link:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 100%;
    margin-bottom: 2rem;
}

@media (min-width: 992px) {
    .sidebar {
        width: 300px;
        margin-left: 2rem;
        margin-bottom: 0;
    }
}

.sidebar .content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.sidebar section {
    margin-bottom: 1.5rem;
}

.sidebar section:last-child {
    margin-bottom: 0;
}

.sidebar .header {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar div {
    padding: 0.5rem 0;
}

.sidebar a {
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s;
}

.sidebar a:hover {
    color: var(--primary);
    text-decoration: none;
}

.front-page-button {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.front-page-button .button {
    width: 100%;
    justify-content: center;
    padding: 1rem;
}

/* ============================================
   KNOWLEDGE BASE
   ============================================ */
#kb {
    list-style: none;
    margin: 2rem 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

#kb > li {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#kb > li:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    transform: translateY(-2px);
}

#kb > li > i {
    color: var(--primary);
    font-size: 2.5rem;
    flex-shrink: 0;
}

#kb > li > div {
    margin-left: 0 !important;
    flex: 1;
}

#kb > li h4 {
    margin: 0 0 0.75rem;
}

#kb > li h4 a {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    line-height: 1.4;
}

#kb > li h4 a:hover {
    color: var(--primary);
    text-decoration: none;
}

#kb > li h4 span {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.875rem;
}

#kb > li .faded {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.6;
}

#kb > li p {
    margin: 0.5rem 0;
}

#kb > li .popular-faq {
    padding: 0.5rem 0;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

#kb > li .popular-faq i {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

#kb > li .popular-faq a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9375rem;
    line-height: 1.5;
}

#kb > li .popular-faq a:hover {
    color: var(--primary);
    text-decoration: none;
}

#kb > li > div > div:last-child {
    margin-top: auto;
}

/* KB sidebar */
.kb-sidebar {
    width: 100%;
    margin-top: 2rem;
}

@media (min-width: 992px) {
    .kb-sidebar {
        width: 300px;
        margin-left: 2rem;
        margin-top: 0;
    }
}

/* KB search */
#kb-search {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

#kb-search #query {
    width: 100%;
    max-width: 400px;
}

#kb-search #searchSubmit {
    margin-left: 0.5rem;
}

#kb-search #breadcrumbs {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

#kb-search #breadcrumbs a {
    color: var(--primary);
    text-decoration: none;
}

#kb-search #breadcrumbs a:hover {
    text-decoration: underline;
}

.featured-category {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.featured-category i {
    color: var(--primary);
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.category-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.article-headline {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
}

.article-headline:last-child {
    border-bottom: none;
}

.article-title a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
}

.article-title a:hover {
    color: var(--primary);
    text-decoration: none;
}

.article-teaser {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* KB specific */
#kb li > i {
    min-width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.popular-faq {
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.popular-faq i {
    color: var(--text-muted);
}

.popular-faq a {
    color: var(--text-secondary);
    text-decoration: none;
}

.popular-faq a:hover {
    color: var(--primary);
    text-decoration: none;
}

.faded {
    color: var(--text-muted);
}

/* ============================================
   SEARCH & FILTERS
   ============================================ */
.search.well {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.search.well form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.search.well input[type="text"] {
    flex: 1;
    min-width: 200px;
}

.states {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.states a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.states a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.states a.active {
    background: var(--primary);
    color: white;
}

.states .divider {
    color: var(--border-light);
}

.clear-filters {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.clear-filters:hover {
    color: var(--danger);
    text-decoration: none;
}

/* ============================================
   PAGINATION
   ============================================ */
#pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 2rem 0;
    padding: 0;
    list-style: none;
}

#pagination li {
    list-style: none;
}

#pagination li a,
#pagination .active,
#pagination .previousOff,
#pagination .nextOff {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s;
}

#pagination li a {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

#pagination li a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#pagination .active {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    border: none;
}

#pagination .previousOff,
#pagination .nextOff {
    color: var(--text-muted);
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    cursor: not-allowed;
}

/* ============================================
   UTILITIES
   ============================================ */
.clear { clear: both; }
.hidden { display: none !important; }
.faded { color: var(--text-muted); }
.centered { text-align: center; }
.pull-left { float: left; }
.pull-right { float: right; }
.flush-left { text-align: left; }
.flush-right { text-align: right; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   LOADING
   ============================================ */
#overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

#loading {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem 3rem;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    text-align: center;
}

#loading h4 {
    margin: 0 0 0.5rem;
    color: var(--text-primary);
    font-weight: 600;
}

#loading p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

#loading::before {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    #header {
        padding: 0.75rem 1rem;
        height: auto;
        min-height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
    }
    
    #logo {
        order: 1;
        flex: 1;
        justify-content: flex-start;
    }
    
    #header .pull-right {
        order: 2;
        width: auto;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
    }
    
    #header p {
        font-size: 0.8125rem;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
        margin: 0;
    }
    
    /* Hide theme toggle in header on mobile - it's in nav now */
    #header .theme-toggle {
        display: none;
    }
    
    /* Mobile navigation dropdown */
    #nav {
        order: 3;
        width: 100%;
        padding: 0;
        margin-top: 0.75rem;
        border-top: 1px solid var(--border-light);
        position: relative;
        cursor: pointer;
    }
    
    #nav::before {
        content: "☰ Меню";
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.75rem 1rem;
        font-weight: 500;
        color: var(--text-secondary);
    }
    
    #nav:hover::before,
    #nav:active::before {
        color: var(--text-primary);
    }
    
    #nav ul {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0;
        padding: 0.5rem 0;
    }
    
    #nav li {
        width: 100%;
    }
    
    #nav li a {
        justify-content: flex-start;
        padding: 0.75rem 1rem;
        border-radius: 0;
        border-bottom: 1px solid var(--border-light);
    }
    
    #nav li:last-child a {
        border-bottom: none;
    }
    
    /* Mobile theme toggle in nav */
    #nav .mobile-theme-toggle {
        border-top: 1px solid var(--border-light);
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }
    
    #nav .mobile-theme-toggle .theme-toggle {
        width: 100%;
        display: flex;
        justify-content: center;
        background: transparent;
        border: 1px solid var(--border-light);
        border-radius: var(--radius);
        padding: 0.75rem 1rem;
    }
    
    #content {
        padding: 1rem;
    }
    
    .landing-hero {
        padding: 2rem 1rem;
    }
    
    .landing-hero h1 {
        font-size: 1.25rem;
        flex-direction: column;
    }
    
    .search-form form {
        flex-direction: column;
    }
    
    .search-form button {
        width: 100%;
    }
    
    .action-cards {
        grid-template-columns: 1fr;
    }
    
    #ticketInfo .ticket-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    #ticketInfo .ticket-actions {
        width: 100%;
        justify-content: flex-start;
    }
    
    .ticket-meta-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .meta-row {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .meta-value {
        text-align: left;
    }
    
    /* Thread entries mobile */
    .thread-entry {
        padding: 1rem;
    }
    
    .thread-entry .avatar {
        position: static;
        width: 32px;
        height: 32px;
        margin-bottom: 0.75rem;
    }
    
    .thread-entry .avatar.pull-left,
    .thread-entry .avatar.pull-right {
        left: auto;
        right: auto;
    }
    
    .thread-entry .header {
        flex-wrap: wrap;
    }
    
    .thread-entry .header-left {
        width: 100%;
        order: 1;
    }
    
    .thread-entry .header-right {
        width: 100%;
        justify-content: flex-end;
        order: 2;
        margin-top: 0.5rem;
    }
    
    .thread-entry .header-left .title {
        width: 100%;
    }
    
    /* Thread events mobile */
    .thread-event {
        padding: 0.75rem 1rem;
    }
    
    .thread-event .avatar {
        width: 20px;
        height: 20px;
    }
    
    /* KB mobile */
    #kb {
        grid-template-columns: 1fr;
    }
    
    /* Table mobile */
    #ticketTable,
    #ticketTable thead,
    #ticketTable tbody,
    #ticketTable th,
    #ticketTable td,
    #ticketTable tr {
        display: block;
    }
    
    #ticketTable thead {
        position: absolute;
        left: -9999px;
    }
    
    #ticketTable tbody tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-light);
        border-radius: var(--radius);
        padding: 1rem;
    }
    
    #ticketTable td {
        padding: 0.5rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border-light);
    }
    
    #ticketTable td:last-child {
        border-bottom: none;
    }
    
    #ticketTable td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.8125rem;
        text-transform: uppercase;
    }
    
    /* Forms mobile */
    #ticketForm table,
    #ticketForm tr,
    #ticketForm td {
        display: block;
        width: 100%;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    /* Alerts mobile */
    #msg_notice, #msg_warning, #msg_error, #msg_info,
    .notice_bar, .warning_bar, .error_bar, .warning-banner {
        padding: 1rem;
        font-size: 0.875rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    #msg_info i {
        font-size: 1.5rem;
    }
    
    /* Sidebar mobile */
    .sidebar {
        width: 100%;
        margin: 0 0 1.5rem 0;
    }
    
    .front-page-button {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .front-page-button .button {
        width: 100%;
    }
    
    /* Pagination mobile */
    #pagination {
        flex-wrap: wrap;
    }
    
    /* Action buttons mobile */
    .action-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }
    
    /* Ticket header mobile */
    #ticketInfo .ticket-title h1 {
        font-size: 1.125rem;
        flex-wrap: wrap;
    }
    
    #ticketInfo .ticket-title h1 small {
        width: 100%;
        margin-left: 0;
        margin-top: 0.25rem;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .thread-entry .avatar {
        width: 28px;
        height: 28px;
    }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
    body {
        background: white;
        color: black;
    }
    
    #header, #nav, #footer, .sidebar, .action-button, #reply {
        display: none !important;
    }
    
    #container {
        max-width: 100%;
        box-shadow: none;
    }
}
