* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    line-height: 1.5;
}

/* Navbar */
.navbar {
    background: #1d1d1f;
    color: #fff;
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-user { color: #86868b; font-size: 13px; }
.nav-link { color: #86868b; text-decoration: none; font-size: 13px; }
.nav-link:hover { color: #fff; }

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-primary { background: #0071e3; color: #fff; }
.btn-primary:hover { background: #0062cc; }
.btn-secondary { background: #e8e8ed; color: #1d1d1f; }
.btn-secondary:hover { background: #d2d2d7; }
.btn-outline { background: transparent; border: 1px solid #d2d2d7; color: #1d1d1f; }
.btn-outline:hover { background: #f5f5f7; }
.btn-active { background: #1d1d1f; color: #fff; border: 1px solid #1d1d1f; }

/* Alerts */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 12px;
}
.page-header h1 { font-size: 24px; font-weight: 700; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.back-link { color: #0071e3; text-decoration: none; font-size: 13px; display: block; margin-bottom: 4px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #d2d2d7;
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 8px 16px;
    text-decoration: none;
    color: #86868b;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}
.tab:hover { color: #1d1d1f; }
.tab.active { color: #0071e3; border-bottom-color: #0071e3; }
.count {
    background: #e8e8ed;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 4px;
}

/* Ticket table */
.ticket-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ticket-table th {
    background: #fafafa;
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #86868b;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ticket-table td {
    padding: 12px 16px;
    font-size: 14px;
    border-top: 1px solid #f0f0f0;
}
.ticket-table tbody tr { cursor: pointer; transition: background 0.1s; }
.ticket-table tbody tr:hover { background: #f5f5f7; }
.ticket-id { color: #86868b; font-weight: 500; }
.ticket-subject { font-weight: 600; }
.ticket-time { color: #86868b; font-size: 13px; white-space: nowrap; }

/* Mobile ticket cards (replaces table on small screens) */
.ticket-cards { display: none; }
.ticket-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    text-decoration: none;
    color: inherit;
    display: block;
}
.ticket-card:active { background: #f5f5f7; }
.ticket-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.ticket-card-id { color: #86868b; font-size: 13px; font-weight: 500; }
.ticket-card-subject { font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.ticket-card-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ticket-card-party { color: #86868b; font-size: 13px; }
.ticket-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
}
.ticket-card-assignee { color: #86868b; font-size: 13px; }
.ticket-card-time { color: #86868b; font-size: 12px; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: #86868b; }
.empty-state p { margin-bottom: 16px; font-size: 16px; }

/* Ticket detail */
.ticket-meta {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.meta-row { display: flex; flex-wrap: wrap; gap: 24px; }
.meta-item { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta-label { font-size: 11px; font-weight: 600; color: #86868b; text-transform: uppercase; letter-spacing: 0.5px; }
.meta-item span { word-break: break-word; }

.ticket-description {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ticket-description h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.ticket-description p { color: #424245; white-space: pre-wrap; }

/* Timeline */
.timeline {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.timeline h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.timeline-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid #f0f0f0;
}
.timeline-item:first-of-type { border-top: none; }
.timeline-marker {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}
.marker-default { background: #d2d2d7; }
.marker-email { background: #10b981; }
.marker-sent { background: #f59e0b; }
.marker-status { background: #8b5cf6; }
.marker-comment { background: #3b82f6; }
.timeline-content { flex: 1; min-width: 0; }
.timeline-header { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.event-type { font-size: 12px; font-weight: 600; text-transform: uppercase; color: #86868b; }
.event-by { font-size: 13px; font-weight: 500; }
.event-time { font-size: 12px; color: #86868b; margin-left: auto; }
.event-body { font-size: 14px; color: #424245; white-space: pre-wrap; word-break: break-word; }
.email-meta { margin-top: 4px; color: #86868b; }

.event-email_received { background: #f0fdf4; border-radius: 8px; padding: 12px; margin: 4px 0; }
.event-email_sent { background: #fffbeb; border-radius: 8px; padding: 12px; margin: 4px 0; }

/* Attachments */
.event-attachments { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f5f5f7;
    border: 1px solid #e8e8ed;
    border-radius: 6px;
    text-decoration: none;
    color: #1d1d1f;
    font-size: 13px;
    transition: background 0.15s;
}
.attachment-link:hover { background: #e8e8ed; }
.att-icon { font-size: 14px; }
.att-name { font-weight: 500; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { color: #86868b; font-size: 11px; }

/* File upload in forms */
.file-upload { margin-bottom: 10px; }
.file-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.file-input { display: none; }
.file-names { font-size: 13px; color: #86868b; }

/* Send email form */
.send-email-form {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 3px solid #f59e0b;
}
.send-email-form h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.send-email-form .form-group { margin-bottom: 12px; }
.send-email-form input,
.send-email-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
}
.send-email-form textarea { resize: vertical; }
.send-email-form input:focus,
.send-email-form textarea:focus { outline: none; border-color: #f59e0b; }
.input-disabled { background: #f5f5f7; color: #86868b; }
.btn-send { background: #f59e0b; color: #fff; padding: 8px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; border: none; cursor: pointer; }
.btn-send:hover { background: #d97706; }

/* Comment form */
.comment-form {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.comment-form h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.comment-form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 10px;
}
.comment-form textarea:focus { outline: none; border-color: #0071e3; }

/* Quick status */
.quick-status {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.quick-status h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
.ticket-form {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #424245;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0071e3;
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Login */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #f5f5f7;
}
.login-card {
    background: #fff;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    width: 360px;
    max-width: calc(100vw - 32px);
}
.login-card h1 { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: #86868b; margin-bottom: 24px; font-size: 15px; }

/* ===== Mobile responsive ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 12px; gap: 8px; }
    .nav-right { gap: 8px; }
    .nav-user { display: none; }
    .container { padding: 16px 12px; }

    .page-header { flex-direction: column; gap: 8px; }
    .page-header h1 { font-size: 20px; }
    .header-actions { width: 100%; }
    .header-actions .btn { flex: 1; text-align: center; }

    /* Tabs scroll horizontally */
    .tabs { gap: 0; }
    .tab { padding: 8px 10px; font-size: 13px; }

    /* Hide table, show cards */
    .ticket-table { display: none; }
    .ticket-cards { display: block; }

    /* Meta wraps vertically */
    .meta-row { gap: 16px; }
    .meta-item { min-width: 45%; }

    /* Forms stack */
    .form-row { flex-direction: column; gap: 0; }
    .ticket-form { padding: 16px; }

    /* Status buttons wrap */
    .status-buttons { gap: 6px; }
    .status-buttons .btn { font-size: 12px; padding: 5px 8px; }

    /* Timeline compact */
    .timeline { padding: 14px; }
    .timeline-header { gap: 4px; }
    .event-time { margin-left: 0; width: 100%; }

    /* Send email form */
    .send-email-form { padding: 14px; }
    .comment-form { padding: 14px; }
    .quick-status { padding: 14px; }
}

@media (max-width: 480px) {
    .page-header h1 { font-size: 18px; }
    .meta-item { min-width: 100%; }
    .header-actions { flex-wrap: wrap; }
}
