/* CSS Variables */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --sidebar-width: 260px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Layout */
.app {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 100;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px;
}

/* Tooltip styles */
.nav-tooltip {
    position: fixed;
    background: #1e293b;
    border: 1px solid #334155;
    padding: 8px 14px;
    border-radius: 6px;
    white-space: nowrap;
    font-size: 0.875rem;
    color: #fff;
    z-index: 99999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.nav-tooltip.visible {
    opacity: 1;
}

/* Widget table styles */
.widget-table-container {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
}

.widget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    table-layout: fixed;
}

.widget-table td,
.widget-table th {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    padding: 6px 8px;
}

.widget-table td:first-child,
.widget-table th:first-child {
    width: 30px;
    max-width: 30px;
}

.widget-table td:last-child,
.widget-table th:last-child {
    width: 60px;
    max-width: 60px;
    text-align: right;
}

.widget-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.widget-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.widget-table tbody tr {
    cursor: pointer;
    transition: background 0.15s ease;
}

.widget-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.1);
}

.widget-table .count-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.8rem;
}

.widget-table .contact-name {
    font-weight: 500;
}

.widget-table .company-name {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Compact table variant */
.widget-table.compact th,
.widget-table.compact td {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.widget-table.compact .count-badge {
    padding: 2px 8px;
    font-size: 0.75rem;
}

/* Stat widgets - 1 column x 1 row (6 across) */
.widget.stat-widget {
    grid-column: span 1;
    grid-row: span 1;
    justify-self: stretch;
    align-self: start;
    height: 100px !important;
    max-height: 100px !important;
    min-height: 100px !important;
    min-width: 0 !important;
    width: 100% !important;
    overflow: hidden;
    padding: 0 !important;
}

.widget.stat-widget .stat-card {
    margin: 0;
    height: 100px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 8px 12px;
    gap: 4px;
    box-sizing: border-box;
    border-radius: var(--radius);
}

.widget.stat-widget .stat-label {
    font-size: 0.75rem;
    line-height: 1.2;
    margin-bottom: 4px;
}

.widget.stat-widget .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 4px;
}

.widget.stat-widget .stat-detail {
    font-size: 0.65rem;
    line-height: 1.2;
    color: var(--text-secondary);
}

.widget.stat-widget .stat-card.clickable {
    cursor: pointer;
}

.widget.stat-widget .stat-card.clickable:hover {
    background: rgba(59, 130, 246, 0.1);
}

.widget.stat-widget .widget-drag-handle {
    top: 4px;
    right: 4px;
}

/* Kill rate summary in modal */
.kill-rate-summary {
    display: flex;
    gap: 24px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.summary-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.summary-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.summary-value.text-success {
    color: #10b981;
}

.summary-value.text-danger {
    color: #ef4444;
}

.sidebar.collapsed .sidebar-header h1,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .status-text,
.sidebar.collapsed .connection-status {
    display: none;
    visibility: hidden;
    width: 0;
    opacity: 0;
}

.sidebar.collapsed .nav-icon {
    margin: 0;
    font-size: 1.1rem;
}

.sidebar.collapsed .sidebar-header {
    padding: 10px;
    justify-content: center;
}

.sidebar.collapsed .sidebar-toggle {
    position: static;
    margin: 0 auto;
}

.sidebar-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h1 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
}

/* User info in sidebar */
.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.78rem;
}

.user-role {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.sidebar.collapsed .sidebar-user {
    padding: 8px;
    justify-content: center;
}

.sidebar.collapsed .user-info {
    display: none;
}

/* Card header row */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header-row h3 {
    margin: 0;
}

/* Form styles */
.form-inline .form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    min-width: 200px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Modal small */
.modal-small {
    max-width: 500px;
}

/* Permissions table */
.permissions-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.permissions-table th,
.permissions-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.permissions-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
}

.permissions-table td:last-child {
    text-align: center;
    width: 60px;
}

.permissions-table th:last-child {
    text-align: center;
    width: 60px;
}

.permissions-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

.permissions-note {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-style: italic;
    margin: 4px 0;
}

/* Company access checkboxes in user modal */
.company-access-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
}

.company-access-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.company-access-item:last-child {
    border-bottom: none;
}

.company-access-item:hover {
    background: rgba(59, 130, 246, 0.05);
}

.company-access-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.company-access-item label {
    cursor: pointer;
    font-size: 0.9rem;
    margin: 0;
}

.company-access-empty {
    padding: 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
}

/* Company Dashboard Section */
.company-section {
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 4px;
}

.company-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    user-select: none;
    transition: color 0.2s;
}

.company-section-header:hover {
    color: var(--text-primary);
}

.company-section-header .chevron {
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.company-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.company-section-list {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

.company-section.collapsed .company-section-list {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

/* Compact company nav items */
.company-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.78rem;
    border-radius: 4px;
    margin: 1px 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.company-nav-item:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--text-primary);
}

.company-nav-item.active {
    background: var(--accent);
    color: white;
}

.company-nav-item .company-dot {
    width: 6px;
    height: 6px;
    min-width: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.company-nav-item.active .company-dot {
    background: white;
}

.company-nav-item .company-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Add company tab button */
.company-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
    margin: 2px 6px 4px;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.15s;
}

.company-add-btn:hover {
    opacity: 1;
    background: rgba(59, 130, 246, 0.1);
    color: var(--text-primary);
}

.company-add-btn .add-plus {
    font-size: 0.8rem;
    font-weight: bold;
}

/* Hide company section when sidebar collapsed */
.sidebar.collapsed .company-section {
    display: none;
}

/* Company search results */
.company-search-results {
    max-height: 300px;
    overflow-y: auto;
}

.company-search-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.company-search-item:hover:not(.disabled) {
    background: rgba(59, 130, 246, 0.1);
}

.company-search-item.disabled {
    opacity: 0.5;
    cursor: default;
}

.company-search-item .company-name {
    font-size: 0.9rem;
}

.company-search-item .add-icon {
    color: var(--accent);
    font-weight: bold;
    font-size: 1.2rem;
}

.company-search-item .badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: var(--bg-primary);
    border-radius: 10px;
    color: var(--text-secondary);
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.badge-admin {
    background: rgba(139, 92, 246, 0.2);
    color: #8b5cf6;
}

.badge-user {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.badge-viewer {
    background: rgba(148, 163, 184, 0.2);
    color: #94a3b8;
}

/* Action buttons */
.action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 1rem;
    transition: background 0.2s ease;
}

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

.action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.2);
}

.sidebar-toggle {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.sidebar-nav {
    flex: 1;
    padding: 8px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.82rem;
    border-radius: var(--radius);
    margin-bottom: 2px;
    transition: all 0.2s ease;
}

.nav-item:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent);
    color: white;
}

.nav-icon {
    font-size: 0.9rem;
}

.sidebar-footer {
    padding: 8px 14px;
    border-top: 1px solid var(--border);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

.status-dot.connected {
    background: var(--success);
}

.status-dot.disconnected {
    background: var(--danger);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 8px 12px;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
    transition: margin-left 0.3s ease, width 0.3s ease, max-width 0.3s ease, border-color 0.5s ease;
    border: 20px solid transparent;
    box-sizing: border-box;
}

.main-content.alert-new-tickets {
    border-color: #ef4444;
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: #ef4444; }
    50% { border-color: #b91c1c; }
}

.sidebar-collapsed .main-content {
    margin-left: 60px;
    width: calc(100% - 60px);
    max-width: calc(100vw - 60px);
}

/* Views */
.view {
    display: none;
}

.view.active {
    display: block;
}

.view-header {
    margin-bottom: 32px;
}

.view-header.compact {
    margin-bottom: 6px;
}

.view-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.view-header.compact h2 {
    font-size: clamp(1rem, 2vh, 1.5rem);
    margin-bottom: 0;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
    max-width: 100%;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.stat-card .stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .stat-icon {
    font-size: 2rem;
    margin-bottom: 12px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(8px, 1vh, 16px);
    margin-bottom: 0;
    box-shadow: var(--shadow);
    max-width: 100%;
    overflow: hidden;
}

/* Large chart widgets - span 2 columns (3 across), height auto */
.card-large {
    grid-column: span 2 !important;
    grid-row: span 1;
    height: 350px;
    max-height: 350px;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px 12px;
}

.card-large h3 {
    font-size: clamp(0.7rem, 1vw, 0.9rem);
    margin-bottom: 2px;
}

.card-large .chart-subtitle {
    font-size: clamp(0.5rem, 0.7vw, 0.65rem);
    margin-bottom: 4px;
}

.card-large .chart-container {
    height: calc(100% - 50px);
    position: relative;
}

/* Half-width widgets (legacy) */
.card-half {
    grid-column: span 2;
    grid-row: span 1;
    height: 350px;
    max-height: 350px;
    min-width: 0;
    overflow: hidden;
    padding: 8px 12px;
}

.card-half h3 {
    font-size: clamp(0.7rem, 1vw, 0.9rem);
    margin-bottom: 2px;
}

.card-half .chart-subtitle {
    font-size: clamp(0.5rem, 0.7vw, 0.65rem);
    margin-bottom: 4px;
}

.card-half .chart-container {
    height: calc(100% - 50px);
    position: relative;
}

.card-half h3 {
    font-size: clamp(0.8rem, 1.2vw, 1.1rem);
}

.card-half .chart-subtitle {
    font-size: clamp(0.5rem, 0.8vw, 0.75rem);
}

/* Draggable Widgets */
.widgets-container {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: auto;
    grid-auto-flow: dense;
    gap: 8px;
    align-items: start;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.widget {
    position: relative;
    cursor: move;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    resize: none;
    overflow: hidden;
    max-width: 100%;
}

/* Large widgets need minimum dimensions */
.widget.card-large,
.widget.card-half {
    min-height: 300px;
    grid-column: span 2 !important;
    width: 100% !important;
}

.widget:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.widget.dragging {
    opacity: 0.5;
    transform: scale(1.02);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.widget.drag-over {
    border: 2px dashed var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.widget-drag-handle {
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: grab;
    padding: 4px 8px;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity 0.2s ease, background 0.2s ease;
    user-select: none;
}

.widget:hover .widget-drag-handle {
    opacity: 1;
    background: var(--bg-primary);
}

.widget-drag-handle:active {
    cursor: grabbing;
}

.widget-placeholder {
    border: 2px dashed var(--border);
    background: var(--bg-primary);
    border-radius: var(--radius);
    min-height: 200px;
}

/* Resize handle styling */
.widget::-webkit-resizer {
    background: linear-gradient(135deg, transparent 50%, var(--accent) 50%);
    border-radius: 0 0 var(--radius) 0;
}

.widget-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, var(--text-secondary) 50%);
    border-radius: 0 0 var(--radius) 0;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.widget:hover .widget-resize-handle {
    opacity: 1;
    background: linear-gradient(135deg, transparent 50%, var(--accent) 50%);
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

/* Table List */
.table-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.table-item {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.table-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.table-item .table-name {
    font-weight: 500;
    color: var(--text-primary);
}

/* Table Select */
.table-select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 200px;
    cursor: pointer;
}

.table-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Filters */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-group input,
.filter-group select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-group input::placeholder {
    color: var(--text-secondary);
}

.filter-actions {
    display: flex;
    gap: 12px;
}

#filteredCount {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: normal;
}

/* Table Container */
.table-container {
    overflow-x: auto;
    max-width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-primary);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.data-table tr:hover td {
    background: rgba(59, 130, 246, 0.05);
}

.data-table td {
    color: var(--text-primary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.pagination button {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 16px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--accent);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .page-info {
    display: flex;
    align-items: center;
    padding: 0 16px;
    color: var(--text-secondary);
}

/* Query Editor */
.query-editor {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.query-editor textarea {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    min-height: 150px;
    resize: none;
}

.query-editor textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

/* Utilities */
.loading {
    color: var(--text-secondary);
    font-style: italic;
}

.placeholder {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.error {
    color: var(--danger);
    padding: 16px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--radius);
}

/* Table Info */
.table-info {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.column-badge {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.8rem;
}

.column-badge .column-name {
    font-weight: 600;
    color: var(--accent);
}

.column-badge .column-type {
    color: var(--text-secondary);
    margin-left: 8px;
}

/* Sync View */
.sync-description {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.sync-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.btn-secondary {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.btn-warning {
    background: var(--warning);
    color: #000;
    border: none;
}

.btn-warning:hover {
    background: #d97706;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sync-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius);
    display: none;
}

.sync-result.success {
    display: block;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.sync-result.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.sync-result.loading {
    display: block;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
}

.sync-times {
    display: grid;
    gap: 12px;
}

.sync-time-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.sync-time-item .label {
    font-weight: 500;
    color: var(--text-primary);
}

.sync-time-item .time {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.schedule-info {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.schedule-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.schedule-icon {
    font-size: 1.5rem;
}

.schedule-name {
    flex: 1;
    font-weight: 500;
}

.schedule-time {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.scheduler-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.scheduler-status {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.status-indicator {
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.875rem;
}

.status-indicator.stopped {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.status-indicator.running {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* Management Dashboard */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
    max-width: 100%;
}

.chart-card {
    min-height: 400px;
}

.chart-card-wide {
    min-height: 350px;
}

.chart-container {
    position: relative;
    height: 320px;
    width: 100%;
}

.chart-container-wide {
    position: relative;
    height: 300px;
    width: 100%;
}

.chart-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 16px;
    margin-top: -8px;
}

.stat-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.kill-rate-card.success .stat-value {
    color: var(--success);
}

.kill-rate-card.warning .stat-value {
    color: var(--warning);
}

.kill-rate-card.danger .stat-value {
    color: var(--danger);
}

@media (max-width: 1200px) {
    .charts-row {
        grid-template-columns: 1fr;
    }
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-large {
    max-width: 900px;
    width: 95%;
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
}

.pagination-controls button {
    min-width: 100px;
}

.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pageInfo {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 120px;
    text-align: center;
}

.ticket-summary {
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Tab buttons for kill rate view */
.tab-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.tab-buttons .btn {
    min-width: 120px;
}

/* Clickable table rows */
.data-table tr.clickable-row {
    cursor: pointer;
    transition: background 0.2s ease;
}

.data-table tr.clickable-row:hover {
    background: rgba(59, 130, 246, 0.1);
}

/* Ticket Detail View */
.ticket-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.ticket-detail-item {
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
}

.ticket-detail-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.ticket-detail-value {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.ticket-detail-full {
    grid-column: span 2;
}

.ticket-description {
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    white-space: pre-wrap;
    font-size: 0.9rem;
    line-height: 1.6;
    max-height: 300px;
    overflow-y: auto;
}

.modal-body .data-table {
    font-size: 0.8rem;
}

.modal-body .data-table th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.modal-body .data-table td {
    max-width: 250px;
}

.ticket-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.ticket-link:hover {
    text-decoration: underline;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.new {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.status-badge.in-progress {
    background: rgba(139, 92, 246, 0.2);
    color: #8b5cf6;
}

.status-badge.awaiting {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

/* Stale ticket styling */
.stale-row {
    background: rgba(245, 158, 11, 0.1) !important;
}

.stale-row:hover {
    background: rgba(245, 158, 11, 0.15) !important;
}

td.stale {
    color: #f59e0b;
    font-weight: 500;
}

/* Version info in sidebar */
.version-info {
    margin-top: 6px;
    font-size: 0.6rem;
    color: var(--text-secondary);
    opacity: 0.6;
}

.sidebar.collapsed .version-info {
    display: none;
}

/* Environment banner */
.env-banner {
    padding: 4px 12px;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.env-banner.dev {
    background: #f59e0b;
    color: #000;
}

.env-banner.prod {
    display: none !important;
}

/* Deployment section */
.deploy-status-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.deploy-env-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    text-align: center;
}

.deploy-env-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.deploy-env-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: capitalize;
}

.deploy-env-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.deploy-actions {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-warning {
    background: #f59e0b;
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.btn-warning:hover {
    background: #d97706;
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.settings-tab {
    background: transparent;
    border: none;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: all 0.2s;
    position: relative;
}

.settings-tab:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.settings-tab.active {
    background: var(--accent);
    color: white;
}

.settings-tab.active::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
}

.settings-content {
    display: none;
}

.settings-content.active {
    display: block;
}

/* Deploy Actions Grid */
.deploy-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 12px;
}

.deploy-action-item {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.deploy-action-item h4 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.deploy-action-item p {
    margin: 0 0 12px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-danger:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* Database Info Grid */
.db-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.db-info-item {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}

.db-info-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.db-info-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

/* Rollback row highlight */
.data-table tr.rollback-selected {
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
}

.data-table tr.rollback-selectable {
    cursor: pointer;
}

.data-table tr.rollback-selectable:hover {
    background: rgba(59, 130, 246, 0.1);
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
    }
    
    :root {
        --sidebar-width: 200px;
    }
    
    .deploy-actions-grid {
        grid-template-columns: 1fr;
    }
    
    .db-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .app {
        flex-direction: column;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .settings-tabs {
        flex-wrap: wrap;
    }
}
