:root {
    --bg-app: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #1e293b;
    --bg-input: #334155;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    --accent: #38bdf8;
    --accent-hover: #0ea5e9;

    --priority-low: #22c55e;
    --priority-med: #eab308;
    --priority-high: #f97316;
    --priority-crit: #ef4444;

    --font: 'Outfit', sans-serif;

    --border-subtle: rgba(255, 255, 255, 0.1);
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(255, 255, 255, 0.1);
    --header-gradient-start: #fff;
    --header-gradient-end: #94a3b8;
}

[data-theme="light"] {
    --bg-app: #f0f9ff;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;

    --text-primary: #0f172a;
    --text-secondary: #475569;

    --accent: #0ea5e9;
    --accent-hover: #0284c7;

    --border-subtle: rgba(14, 165, 233, 0.15);
    --bg-hover: rgba(14, 165, 233, 0.08);
    --bg-active: rgba(14, 165, 233, 0.15);
    --header-gradient-start: #0284c7;
    --header-gradient-end: #334155;
}

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

body {
    font-family: var(--font);
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

.mobile-header {
    display: none;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    padding: 2rem;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
}

.brand {
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.logo-image {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: cover;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.nav-links {
    list-style: none;
    margin-bottom: 3rem;
}

.nav-link {
    display: block;
    padding: 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dept-list h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
    padding-left: 1rem;
}

.dept-link {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.dept-link:hover {
    color: var(--accent);
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 3rem;
}

/* Forms */
.form-container {
    max-width: 800px;
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, var(--header-gradient-start), var(--header-gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.1);
}

option {
    background-color: var(--bg-card);
    /* Ensure dark background */
    color: var(--text-primary);
}

/* Priority Selector */
.priority-selector {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-input);
    padding: 0.3rem;
    border-radius: 12px;
    width: fit-content;
}

.priority-selector input {
    display: none;
}

.p-label {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.priority-selector input:checked+.p-label {
    color: white;
    font-weight: 500;
}

.priority-selector input:checked+.p-label.low {
    background: var(--priority-low);
}

.priority-selector input:checked+.p-label.med {
    background: var(--priority-med);
}

.priority-selector input:checked+.p-label.high {
    background: var(--priority-high);
}

.priority-selector input:checked+.p-label.crit {
    background: var(--priority-crit);
}

/* File Input matches theme */
input[type="file"]::file-selector-button {
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    margin-right: 1rem;
    cursor: pointer;
}

/* Nav Accordion */
.nav-accordion summary {
    list-style: none;
}

.nav-accordion summary::-webkit-details-marker {
    display: none;
}

.nav-accordion[open] summary {
    background: var(--bg-active);
    /* Highlight when open */
    color: var(--text-primary);
}

.nav-accordion[open] summary span {
    transform: rotate(180deg);
}

input[type="file"]::file-selector-button:hover {
    background: var(--accent);
}

.btn-primary {
    background: var(--accent);
    color: #0f172a;
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    font-size: 1rem;
    transition: transform 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

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

.ticket-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 16px;
    text-decoration: none;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

.ticket-card:hover {
    transform: translateY(-4px);
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.priority-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
}

.priority-badge.Low {
    color: var(--priority-low);
    background: rgba(34, 197, 94, 0.1);
}

.priority-badge.Medium {
    color: var(--priority-med);
    background: rgba(234, 179, 8, 0.1);
}

.priority-badge.High {
    color: var(--priority-high);
    background: rgba(249, 115, 22, 0.1);
}

.priority-badge.Critical {
    color: var(--priority-crit);
    background: rgba(239, 68, 68, 0.1);
}

.ticket-title {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.ticket-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.dept-tag {
    background: var(--bg-hover);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    margin-right: 0.5rem;
}

.status {
    font-weight: 500;
}

.status.Open {
    color: var(--priority-low);
    /* Green-ish for open/new? Or keep accent */
    color: #38bdf8;
    /* Keep accent for Open */
}

.status.In.Progress {
    color: #818cf8;
    /* Indigo */
}

.status.On.Hold {
    color: #fbbf24;
    /* Amber */
}

.status.Closed {
    color: #94a3b8;
    /* Slate/Gray */
}

/* Detail View */
.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    display: inline-block;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.detail-content {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 3rem;
}

.detail-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
}

.meta-info {
    display: flex;
    gap: 3rem;
    margin: 2rem 0;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 2rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-item .label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.description-box p {
    line-height: 1.6;
    color: var(--text-secondary);
}

.attachments-section {
    margin-top: 3rem;
}

.file-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-input);
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    color: var(--text-primary);
    text-decoration: none;
    margin-top: 1rem;
}

/* View Toggle */
.view-toggle {
    display: flex;
    background: var(--bg-input);
    padding: 0.25rem;
    border-radius: 10px;
    gap: 0.25rem;
}

.toggle-btn {
    padding: 0.5rem 0.8rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.toggle-btn:hover:not(.active) {
    color: var(--text-primary);
}

/* Data Table (List View) */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.data-table th {
    text-align: left;
    padding: 1rem 1.5rem;
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

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

.data-table tr:hover {
    background: var(--bg-active);
}

.data-table a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.table-row-link {
    cursor: pointer;
}

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

    .sidebar {
        width: 100%;
        padding: 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
        display: none;
        /* Hidden by default on mobile, toggle needed */
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        overflow-y: auto;
    }

    .sidebar.active {
        display: flex;
    }

    .main-content {
        padding: 1.5rem;
        padding-top: 80px;
        /* Account for mobile header */
    }

    .tickets-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .detail-header {
        flex-direction: column;
        gap: 1rem;
    }

    .meta-info {
        flex-wrap: wrap;
        gap: 1.5rem;
    }

    /* Mobile Header Bar */
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
        background: var(--bg-sidebar);
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 999;
        border-bottom: 1px solid var(--border-subtle);
    }

    .mobile-nav-toggle {
        background: transparent;
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .mobile-header {
        display: none;
    }
}

/* Quill Editor Overrides */
.ql-toolbar {
    background: #e2e8f0;
    border-radius: 12px 12px 0 0;
    border: none !important;
}

.ql-container {
    border: none !important;
    font-family: var(--font) !important;
}

.ql-editor {
    color: var(--text-primary) !important;
    font-family: var(--font) !important;
    font-size: 1rem;
    min-height: 100%;
}

.ql-editor.ql-blank::before {
    color: var(--text-secondary) !important;
    font-style: italic;
}