:root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --panel-border: #e5e7eb;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --secondary: #e2e8f0;
    --danger: #dc2626;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

html,
body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

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

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    font-size: clamp(2rem, 3vw, 3.2rem);
    line-height: 1.05;
    font-weight: 850;
    letter-spacing: 0;
}

h2 {
    font-size: 1.25rem;
    font-weight: 780;
}

.content {
    padding-top: 1.5rem;
}

.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.eyebrow {
    margin-bottom: 0.45rem;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.muted,
.panel-header p,
.ticket-row small {
    color: var(--muted);
}

.panel,
.metric-card,
.auth-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.panel.narrow {
    max-width: 820px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.25rem;
    align-items: start;
}

.admin-breakdown-grid {
    margin-top: 1.25rem;
}

.metric-card {
    padding: 1rem;
}

.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.metric-card strong {
    display: block;
    font-size: 2rem;
    line-height: 1;
}

.count-list,
.monthly-company-list {
    display: grid;
    gap: 0.65rem;
}

.count-row,
.monthly-company-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e2e8f0;
}

.count-row:last-child,
.monthly-company-row:last-child {
    border-bottom: 0;
}

.count-row span,
.monthly-company-row > strong {
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 760;
}

.count-row strong {
    font-size: 1rem;
}

.count-dot {
    --dot-color: #475569;
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    margin-right: 0.45rem;
    border-radius: 999px;
    background: var(--dot-color);
    vertical-align: middle;
}

.company-counts {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.company-count {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    max-width: 100%;
    padding: 0.35rem 0.55rem;
    border: 1px solid #dbe3ef;
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
    font-size: 0.82rem;
    font-weight: 760;
}

.company-count span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.company-count strong {
    color: var(--text);
}

.btn {
    border: 0;
    border-radius: 8px;
    min-height: 2.45rem;
    padding: 0.6rem 0.95rem;
    font-weight: 760;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    color: #ffffff;
    background: var(--primary);
    box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22);
}

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

.btn-secondary {
    color: #0f172a;
    background: var(--secondary);
}

.btn-danger {
    color: #ffffff;
    background: var(--danger);
}

.btn-small {
    min-height: 1.9rem;
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
}

.field {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.field label,
.check-row {
    font-size: 0.82rem;
    font-weight: 800;
    color: #334155;
}

.form-control,
.inline-input {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    min-height: 2.5rem;
    padding: 0.55rem 0.7rem;
    background: #ffffff;
    color: #0f172a;
}

.form-control:focus,
.inline-input:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(15, 118, 110, 0.14);
}

.textarea-lg {
    min-height: 180px;
}

.form-actions,
.button-row,
.table-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
    align-items: end;
}

.action-field {
    margin-bottom: 1rem;
}

.ticket-list {
    display: grid;
    gap: 0.75rem;
}

.ticket-list.compact {
    gap: 0.6rem;
}

.ticket-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.ticket-row:hover {
    border-color: #99f6e4;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.ticket-main {
    min-width: 0;
}

.ticket-row strong,
.ticket-row small {
    display: block;
}

.ticket-number {
    display: inline-block;
    color: var(--primary);
    font-weight: 850;
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
}

.row-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chip {
    --chip-color: #475569;
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    color: var(--chip-color);
    background: color-mix(in srgb, var(--chip-color) 12%, white);
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.chip.closed {
    --chip-color: #334155;
}

.empty-state,
.loading-panel,
.closed-note {
    padding: 2rem;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    text-align: center;
}

.empty-state.compact {
    padding: 1.25rem;
}

.auth-card {
    max-width: 680px;
    padding: 1.5rem;
}

.ticket-detail-grid,
.admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
}

.issue-panel {
    min-width: 0;
}

.ticket-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.description {
    white-space: pre-wrap;
    line-height: 1.65;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0 0;
}

.detail-list dt {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.detail-list dd {
    margin: 0.25rem 0 0;
    font-weight: 750;
}

.timeline {
    display: grid;
    gap: 1rem;
}

.timeline-item {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 0.85rem;
}

.timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 0.35rem;
}

.timeline-body {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.85rem;
    background: #ffffff;
}

.timeline-meta {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.82rem;
    margin-bottom: 0.4rem;
}

.timeline-meta strong {
    color: var(--text);
}

.attachment-list {
    display: grid;
    gap: 0.65rem;
    margin-top: 0.8rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: fit-content;
    max-width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    background: #f8fafc;
    color: var(--text);
    text-decoration: none;
}

.attachment-item:hover {
    border-color: #99f6e4;
    background: #f0fdfa;
}

.attachment-preview-button {
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.attachment-item img {
    width: 84px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
}

.attachment-item span {
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 750;
}

.attachment-item small,
.pending-attachment small {
    color: var(--muted);
    white-space: nowrap;
}

.image-preview-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 3vw, 2rem);
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(8px);
}

.image-preview-dialog {
    display: grid;
    gap: 1rem;
    width: min(1100px, 96vw);
    max-height: 92vh;
    padding: 1rem;
    border: 1px solid rgba(226, 232, 240, 0.24);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.32);
}

.image-preview-header,
.image-preview-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.image-preview-header h2 {
    margin-bottom: 0.2rem;
    overflow-wrap: anywhere;
}

.image-preview-header p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 700;
}

.image-preview-canvas {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    max-height: calc(92vh - 180px);
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}

.image-preview-canvas img {
    display: block;
    max-width: 100%;
    max-height: calc(92vh - 210px);
    object-fit: contain;
}

.reply-box {
    margin-top: 1.25rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 1.25rem;
}

.file-input {
    padding: 0.45rem 0.7rem;
}

.field-error {
    margin-bottom: 1rem;
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 750;
}

.pending-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.pending-attachment {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    max-width: 100%;
    padding: 0.4rem 0.65rem;
    border: 1px solid #dbe3ef;
    border-radius: 999px;
    background: #f8fafc;
    font-size: 0.85rem;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.admin-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.tab-button {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    border-radius: 999px;
    padding: 0.55rem 0.85rem;
    color: #334155;
    font-weight: 800;
}

.tab-button.active {
    color: #ffffff;
    background: #0f172a;
    border-color: #0f172a;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.data-table th,
.data-table td {
    padding: 0.8rem;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: #475569;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.alert-error,
.alert-success {
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.alert-error {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fecaca;
}

.alert-success {
    color: #065f46;
    background: #d1fae5;
    border: 1px solid #a7f3d0;
}

.validation-message,
.text-danger {
    color: #dc2626;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #22c55e;
}

.invalid {
    outline: 1px solid #dc2626;
}

.blazor-error-boundary {
    background: #991b1b;
    color: #ffffff;
    padding: 1rem;
    border-radius: 8px;
}

.darker-border-checkbox.form-check-input {
    border-color: #64748b;
}

@media (min-width: 980px) {
    .ticket-detail-grid {
        grid-template-columns: minmax(0, 1fr) 360px;
        align-items: start;
    }

    .admin-grid {
        grid-template-columns: 380px minmax(0, 1fr);
        align-items: start;
    }
}

@media (max-width: 700px) {
    .page-heading,
    .ticket-row,
    .panel-header {
        flex-direction: column;
        align-items: stretch;
    }

    .row-actions {
        justify-content: flex-start;
    }

    .monthly-company-row {
        align-items: stretch;
        flex-direction: column;
    }

    .company-counts {
        justify-content: flex-start;
    }

    .image-preview-header,
    .image-preview-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .image-preview-canvas {
        min-height: 180px;
    }
}
