/* =============================
   CSS Variables
   ============================= */
:root {
    --ty-primary: #0073aa;
    --ty-primary-hover: #005177;
    --ty-success: #46b450;
    --ty-warning: #ffb900;
    --ty-danger: #dc3232;
    --ty-info: #00a0d2;
    --ty-light: #f8f9fa;
    --ty-dark: #343a40;
    --ty-gray-100: #f8f9fa;
    --ty-gray-200: #e9ecef;
    --ty-gray-300: #dee2e6;
    --ty-gray-400: #ced4da;
    --ty-gray-500: #adb5bd;
    --ty-gray-600: #6c757d;
    --ty-gray-700: #495057;
    --ty-gray-800: #343a40;
    --ty-gray-900: #212529;
    --ty-border-radius: 6px;
    --ty-box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    --ty-transition: all 0.3s ease;
    --ty-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* =============================
   Common Styles
   ============================= */
.ticketyar-wrap {
    font-family: var(--ty-font-family);
    background: #fff;
    padding: 25px;
    margin: 20px 0;
    border: 1px solid var(--ty-gray-300);
    border-radius: var(--ty-border-radius);
    box-shadow: var(--ty-box-shadow);
    line-height: 1.6;
}

.ticketyar-wrap h1,
.ticketyar-wrap h2,
.ticketyar-wrap h3,
.ticketyar-wrap h4,
.ticketyar-wrap h5,
.ticketyar-wrap h6 {
    color: var(--ty-dark);
    margin-top: 0;
    margin-bottom: 1rem;
    font-weight: 600;
}

.ticketyar-wrap h3 {
    font-size: 1.5rem;
    border-bottom: 2px solid var(--ty-primary);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

/* =============================
   Button Styles
   ============================= */
.btn {
    display: inline-block;
    padding: 10px 20px;
    margin: 0 5px 5px 0;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--ty-border-radius);
    transition: var(--ty-transition);
    line-height: 1.4;
    user-select: none;
}

.btn:hover,
.btn:focus {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-primary {
    background: var(--ty-primary);
    color: #fff;
    border-color: var(--ty-primary);
}

.btn-primary:hover {
    background: var(--ty-primary-hover);
    border-color: var(--ty-primary-hover);
    color: #fff;
}

.btn-secondary {
    background: var(--ty-gray-600);
    color: #fff;
    border-color: var(--ty-gray-600);
}

.btn-secondary:hover {
    background: var(--ty-gray-700);
    border-color: var(--ty-gray-700);
    color: #fff;
}

.btn-success {
    background: var(--ty-success);
    color: #fff;
    border-color: var(--ty-success);
}

.btn-success:hover {
    background: #218838;
    border-color: #1e7e34;
    color: #fff;
}

.btn-danger {
    background: var(--ty-danger);
    color: #fff;
    border-color: var(--ty-danger);
}

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
    color: #fff;
}

.btn-warning {
    background: var(--ty-warning);
    color: #212529;
    border-color: var(--ty-warning);
}

.btn-warning:hover {
    background: #e0a800;
    border-color: #d39e00;
    color: #212529;
}

.btn-info {
    background: var(--ty-info);
    color: #fff;
    border-color: var(--ty-info);
}

.btn-info:hover {
    background: #0085a3;
    border-color: #007991;
    color: #fff;
}

.btn-light {
    background: var(--ty-light);
    color: var(--ty-dark);
    border-color: var(--ty-gray-300);
}

.btn-light:hover {
    background: var(--ty-gray-200);
    border-color: var(--ty-gray-400);
    color: var(--ty-dark);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
}

.btn-large {
    padding: 15px 30px;
    font-size: 16px;
    font-weight: 600;
}

/* =============================
   Header Section
   ============================= */
.ty-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--ty-gray-200);
}

.ty-header h3 {
    margin: 0;
    border: none;
    padding: 0;
    font-size: 1.8rem;
    color: var(--ty-primary);
}

.ty-back-link {
    color: var(--ty-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--ty-transition);
}

.ty-back-link:hover {
    color: var(--ty-primary-hover);
    text-decoration: none;
}

/* =============================
   Table Styles
   ============================= */
.ty-tickets-table-wrapper {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: var(--ty-border-radius);
    box-shadow: var(--ty-box-shadow);
}

.ty-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: #fff;
    font-size: 14px;
}

.ty-table th,
.ty-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--ty-gray-200);
    vertical-align: middle;
}

.ty-table th {
    background: linear-gradient(135deg, var(--ty-primary) 0%, var(--ty-primary-hover) 100%);
    color: #fff;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.ty-table tbody tr {
    transition: var(--ty-transition);
}

.ty-table tbody tr:hover {
    background: var(--ty-gray-100);
}

.ty-table tbody tr:last-child td {
    border-bottom: none;
}

.ticket-title-link {
    color: var(--ty-primary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--ty-transition);
}

.ticket-title-link:hover {
    color: var(--ty-primary-hover);
    text-decoration: underline;
}

.ty-actions {
    white-space: nowrap;
}

.ty-actions .btn {
    margin: 2px;
}

/* =============================
   Status & Priority Badges
   ============================= */
.ty-status-badge,
.ty-priority-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.ty-status-badge.ty-status-waiting_operator {
    background: linear-gradient(135deg, var(--ty-warning) 0%, #ffc107 100%);
    color: #212529;
}

.ty-status-badge.ty-status-answered {
    background: linear-gradient(135deg, var(--ty-success) 0%, #28a745 100%);
    color: #fff;
}

.ty-status-badge.ty-status-closed {
    background: linear-gradient(135deg, var(--ty-gray-600) 0%, var(--ty-gray-700) 100%);
    color: #fff;
}

.ty-priority-badge.ty-priority-high {
    background: linear-gradient(135deg, var(--ty-warning) 0%, #ffc107 100%);
    color: #212529;
}

.ty-priority-badge.ty-priority-urgent {
    background: linear-gradient(135deg, var(--ty-danger) 0%, #dc3545 100%);
    color: #fff;
}

/* =============================
   Filters Section
   ============================= */
.ty-filters {
    background: var(--ty-gray-100);
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: var(--ty-border-radius);
    border: 1px solid var(--ty-gray-300);
}

.ty-filters strong {
    display: inline-block;
    margin-left: 10px;
    color: var(--ty-dark);
    font-weight: 600;
}

.ty-filters .btn {
    margin: 2px;
    padding: 6px 12px;
    font-size: 12px;
}

/* =============================
   Pagination
   ============================= */
.ty-pagination {
    text-align: center;
    margin: 25px 0;
    padding: 20px 0;
}

.ty-pagination .page-numbers {
    display: inline-block;
    margin: 0 3px;
    padding: 8px 12px;
    border: 1px solid var(--ty-gray-300);
    color: var(--ty-primary);
    text-decoration: none;
    border-radius: var(--ty-border-radius);
    transition: var(--ty-transition);
    font-weight: 500;
}

.ty-pagination .page-numbers:hover {
    background: var(--ty-primary);
    color: #fff;
    border-color: var(--ty-primary);
    transform: translateY(-1px);
}

.ty-pagination .current {
    background: var(--ty-primary);
    color: #fff;
    border-color: var(--ty-primary);
}

.ty-pagination .dots {
    background: none;
    border: none;
    color: var(--ty-gray-500);
    cursor: default;
}

.ty-pagination .dots:hover {
    background: none;
    color: var(--ty-gray-500);
    transform: none;
}

/* =============================
   Forms
   ============================= */
.ty-form {
    max-width: 600px;
    margin: 0 auto;
}

.ty-form-group {
    margin-bottom: 20px;
}

.ty-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--ty-dark);
    font-size: 14px;
}

.ty-form-group .required {
    color: var(--ty-danger);
    font-weight: 700;
}

.ty-form input[type="text"],
.ty-form input[type="email"],
.ty-form input[type="password"],
.ty-form input[type="tel"],
.ty-form input[type="url"],
.ty-form input[type="file"],
.ty-form select,
.ty-form textarea {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--ty-gray-300);
    border-radius: var(--ty-border-radius);
    font-size: 14px;
    font-family: inherit;
    transition: var(--ty-transition);
    background: #fff;
}

.ty-form input[type="text"]:focus,
.ty-form input[type="email"]:focus,
.ty-form input[type="password"]:focus,
.ty-form input[type="tel"]:focus,
.ty-form input[type="url"]:focus,
.ty-form select:focus,
.ty-form textarea:focus {
    outline: none;
    border-color: var(--ty-primary);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.ty-form input[type="file"] {
    padding: 8px 12px;
    background: var(--ty-gray-100);
    border-style: dashed;
}

.ty-form input[type="file"]:focus {
    background: #fff;
    border-style: solid;
}

.ty-form textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

.ty-form select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: left 12px center;
    background-repeat: no-repeat;
    background-size: 16px 12px;
    padding-left: 40px;
    appearance: none;
}

.form-text {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: var(--ty-gray-600);
    line-height: 1.4;
}

.ty-form-actions {
    margin-top: 25px;
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid var(--ty-gray-200);
}

.ty-form-actions .btn {
    margin: 0 5px;
}

/* =============================
   Chat Interface
   ============================= */
.ty-ticket-header {
    background: linear-gradient(135deg, var(--ty-primary) 0%, var(--ty-primary-hover) 100%);
    color: #fff;
    padding: 20px;
    border-radius: var(--ty-border-radius) var(--ty-border-radius) 0 0;
    margin: -25px -25px 25px -25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.ty-ticket-title h3 {
    margin: 0;
    color: #fff;
    border: none;
    padding: 0;
    font-size: 1.4rem;
}

.ty-ticket-title .ticket-id {
    opacity: 0.8;
    font-size: 0.9em;
    font-weight: 400;
}

.ty-ticket-meta {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.6;
}

.ty-meta-item {
    display: inline-block;
    margin-left: 15px;
    opacity: 0.9;
}

.ty-meta-item:first-child {
    margin-left: 0;
}

.ty-ticket-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ty-ticket-actions .btn {
    margin: 0;
}

.ty-chat-container {
    max-width: 800px;
    margin: 0 auto 25px;
    background: var(--ty-gray-100);
    border-radius: var(--ty-border-radius);
    padding: 20px;
    max-height: 600px;
    overflow-y: auto;
}

.ty-message {
    display: flex;
    margin: 15px 0;
    animation: fadeInUp 0.3s ease-out;
}

.admin-message {
    justify-content: flex-start;
}

.user-message {
    justify-content: flex-end;
}

.ty-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 12px;
}

.ty-sender {
    font-weight: 600;
    color: var(--ty-primary);
}

.ty-time {
    color: var(--ty-gray-600);
    font-size: 11px;
    direction: ltr;
}

.ty-message-content {
    position: relative;
    max-width: 70%;
    padding: 15px 18px;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    word-wrap: break-word;
    line-height: 1.5;
}

.admin-message .ty-message-content {
    background: linear-gradient(135deg, var(--ty-success) 0%, #28a745 100%);
    color: #fff;
    margin-right: 20px;
}

.user-message .ty-message-content {
    background: linear-gradient(135deg, var(--ty-primary) 0%, var(--ty-primary-hover) 100%);
    color: #fff;
    margin-left: 20px;
}

.ty-message-content::before {
    content: "";
    position: absolute;
    top: 20px;
    width: 0;
    height: 0;
}

.admin-message .ty-message-content::before {
    left: -10px;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid var(--ty-success);
}

.user-message .ty-message-content::before {
    right: -10px;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 10px solid var(--ty-primary);
}

.ty-message-content p {
    margin: 0;
    line-height: 1.6;
}

.ty-message-content p:not(:last-child) {
    margin-bottom: 10px;
}

.ty-message-files {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.2);
}

.ty-message-files strong {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ty-file-item {
    margin-bottom: 6px;
}

.ty-file-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    background: rgba(255,255,255,0.2);
    color: inherit;
    text-decoration: none;
    border-radius: 12px;
    font-size: 12px;
    transition: var(--ty-transition);
}

.ty-file-link:hover {
    background: rgba(255,255,255,0.3);
    color: inherit;
    text-decoration: none;
}

.ty-file-icon {
    margin-left: 6px;
    font-size: 14px;
}

.ty-file-name {
    font-weight: 500;
}

.ty-file-size {
    margin-right: 6px;
    opacity: 0.8;
    font-size: 11px;
}

/* =============================
   Reply Section
   ============================= */
.ty-reply-section {
    background: #fff;
    padding: 25px;
    border-radius: var(--ty-border-radius);
    border: 2px solid var(--ty-gray-200);
    box-shadow: var(--ty-box-shadow);
}

.ty-reply-section h4 {
    margin: 0 0 20px 0;
    color: var(--ty-primary);
    font-size: 1.2rem;
    border-bottom: 2px solid var(--ty-primary);
    padding-bottom: 10px;
}

.ty-reply-form textarea {
    border: 2px solid var(--ty-gray-300);
    border-radius: var(--ty-border-radius);
    padding: 15px;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    min-height: 120px;
}

.ty-reply-form textarea:focus {
    border-color: var(--ty-primary);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

/* =============================
   Alerts & Notifications
   ============================= */
.alert {
    padding: 15px 20px;
    margin: 20px 0;
    border: 1px solid transparent;
    border-radius: var(--ty-border-radius);
    font-size: 14px;
    line-height: 1.5;
}

.alert-success {
    color: #155724;
    background: #d4edda;
    border-color: #c3e6cb;
}

.alert-info {
    color: #0c5460;
    background: #d1ecf1;
    border-color: #bee5eb;
}

.alert-warning {
    color: #856404;
    background: #fff3cd;
    border-color: #ffeaa7;
}

.alert-danger {
    color: #721c24;
    background: #f8d7da;
    border-color: #f5c6cb;
}

.ty-closed-notice {
    text-align: center;
    padding: 20px;
    font-size: 15px;
}

/* =============================
   Empty States
   ============================= */
.ty-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--ty-gray-600);
}

.ty-empty p {
    font-size: 16px;
    margin-bottom: 20px;
}

/* =============================
   Animations
   ============================= */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.ty-pulse {
    animation: pulse 2s infinite;
}

/* =============================
   Responsive Design
   ============================= */
@media (max-width: 768px) {
    .ticketyar-wrap {
        padding: 20px 15px;
        margin: 15px 0;
    }
    
    .ty-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        text-align: center;
    }
    
    .ty-header h3 {
        font-size: 1.4rem;
    }
    
    .ty-tickets-table-wrapper {
        margin: 15px -15px;
        border-radius: 0;
    }
    
    .ty-table th,
    .ty-table td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .ty-table th {
        font-size: 11px;
    }
    
    .ty-actions .btn {
        padding: 4px 8px;
        font-size: 11px;
        margin: 1px;
    }
    
    .ty-filters {
        padding: 15px;
        text-align: center;
    }
    
    .ty-filters strong {
        display: block;
        margin: 0 0 10px 0;
    }
    
    .ty-form {
        max-width: 100%;
    }
    
    .ty-ticket-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        padding: 15px;
        margin: -20px -15px 20px -15px;
    }
    
    .ty-ticket-title {
        margin-bottom: 15px;
    }
    
    .ty-ticket-meta .ty-meta-item {
        display: block;
        margin: 5px 0;
    }
    
    .ty-ticket-actions {
        justify-content: center;
    }
    
    .ty-chat-container {
        padding: 15px;
        margin: 15px -15px;
        border-radius: 0;
    }
    
    .ty-message-content {
        max-width: 85%;
        padding: 12px 15px;
        border-radius: 15px;
    }
    
    .admin-message .ty-message-content {
        margin-right: 10px;
    }
    
    .user-message .ty-message-content {
        margin-left: 10px;
    }
    
    .ty-reply-section {
        padding: 20px 15px;
        margin: 15px -15px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .btn-sm {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .btn-lg,
    .btn-large {
        padding: 12px 20px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .ticketyar-wrap {
        padding: 15px 10px;
        margin: 10px 0;
    }
    
    .ty-header h3 {
        font-size: 1.2rem;
    }
    
    .ty-table th,
    .ty-table td {
        padding: 6px 4px;
        font-size: 11px;
    }
    
    .ty-message-content {
        max-width: 90%;
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .ty-ticket-header {
        padding: 12px 10px;
        margin: -15px -10px 15px -10px;
    }
    
    .ty-ticket-title h3 {
        font-size: 1.1rem;
    }
    
    .ty-chat-container {
        padding: 10px;
        margin: 10px -10px;
    }
    
    .ty-reply-section {
        padding: 15px 10px;
        margin: 10px -10px;
    }
    
    .ty-form input,
    .ty-form select,
    .ty-form textarea {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .btn-sm {
        padding: 5px 8px;
        font-size: 10px;
    }
}

/* =============================
   Print Styles
   ============================= */
@media print {
    .ticketyar-wrap {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .ty-ticket-header {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #000;
    }
    
    .ty-ticket-actions,
    .ty-reply-section,
    .btn {
        display: none !important;
    }
    
    .ty-message-content {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #000;
    }
    
    .ty-chat-container {
        background: #fff !important;
        box-shadow: none;
        max-height: none;
        overflow: visible;
    }
    
    .ty-status-badge,
    .ty-priority-badge {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #000;
    }
}

/* =============================
   Dark Mode Support
   ============================= */
@media (prefers-color-scheme: dark) {
    .ticketyar-wrap {
        background: #1a1a1a;
        color: #e0e0e0;
        border-color: #333;
    }
    
    .ty-table th {
        background: linear-gradient(135deg, #333 0%, #444 100%);
    }
    
    .ty-table tbody tr:hover {
        background: #2a2a2a;
    }
    
    .ty-form input,
    .ty-form select,
    .ty-form textarea {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .ty-chat-container {
        background: #2a2a2a;
    }
    
    .ty-reply-section {
        background: #1a1a1a;
        border-color: #333;
    }
}

/* =============================
   High Contrast Mode
   ============================= */
@media (prefers-contrast: high) {
    .ticketyar-wrap {
        border-width: 2px;
    }
    
    .btn {
        border-width: 2px;
        font-weight: 700;
    }
    
    .ty-form input,
    .ty-form select,
    .ty-form textarea {
        border-width: 2px;
    }
    
    .ty-status-badge,
    .ty-priority-badge {
        border: 2px solid currentColor;
    }
}

/* =============================
   Reduced Motion
   ============================= */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .ty-message {
        animation: none;
    }
    
    .btn:hover {
        transform: none;
    }
}
