:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --secondary: #64748b;
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --nav-height: 72px;
}

/* Base Layout Reset */
html, body {
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Disable page scroll */
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
}

/* Fixed Header */
header { flex-shrink: 0; }
.navbar { background: #0f172a !important; height: var(--nav-height); }

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Important for flex children to scroll */
}

.content-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2rem;
  min-height: 0; /* Important for children to scroll */
}

/* Non-scrollable elements at top */
.page-heading { flex-shrink: 0; margin-bottom: 1.5rem; }
.filter-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  background: #fff;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  flex-shrink: 0;
}

.filter-bar .input-group {
  flex: 1;
}

.filter-bar .form-control,
.filter-bar .form-select,
.filter-bar .input-group-text {
  height: 44px;
  border-color: #e2e8f0;
  font-size: 0.9rem;
  background-color: #f8fafc;
}

.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
  background-color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-bar .input-group-text {
  border-right: none;
  color: var(--text-muted);
  padding-left: 1.25rem;
}

.filter-bar .form-control {
  border-left: none;
}

.filter-bar .form-select {
  width: auto;
  min-width: 160px;
  flex-shrink: 0;
  cursor: pointer;
}

.filter-bar .btn {
  height: 44px;
  flex-shrink: 0;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

/* The Scrollable Table Container */
.table-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Force height calculation from flex */
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.table-scroll {
  flex: 1;
  overflow-y: auto; /* Internal scrolling! */
  overflow-x: auto;
}

/* Table Design */
.table { margin-bottom: 0; width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead { position: sticky; top: 0; z-index: 10; }
.table thead th { background: #f8fafc !important; color: #64748b; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; padding: 1rem 1.5rem; border-bottom: 2px solid var(--border); }
.table tbody td { padding: 1rem 1.5rem; vertical-align: middle; border-bottom: 1px solid #f1f5f9; }

/* For pages that need full scroll (e.g. Details) */
.scroll-view {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 2rem;
}

/* Ticket Details Layout */
.ticket-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1.5rem; }
.detail-block { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.side-panel { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; }
.meta-icon { width: 40px; height: 40px; background: #f1f5f9; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--primary); margin-right: 12px; font-size: 1.25rem; }

/* Timeline & Comments */
.activity-timeline { position: relative; padding-left: 1rem; }
.activity-timeline::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: #e2e8f0; border-radius: 1px; }

.timeline-event { position: relative; padding-left: 1.5rem; margin-bottom: 1.5rem; }
.timeline-event::before { content: ''; position: absolute; left: -1.45rem; top: 0.25rem; width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; border: 2px solid #fff; box-shadow: 0 0 0 2px #e2e8f0; }
.status-change { color: var(--text-muted); font-size: 0.85rem; padding: 0.75rem 1rem; background: #f8fafc; border-radius: 8px; border-left: 3px solid #94a3b8; }

.comment-bubble { background: #f1f5f9; border-radius: 12px; padding: 1.25rem; margin-bottom: 1.5rem; position: relative; border: 1px solid #e2e8f0; }
.comment-bubble.admin { background: #eff6ff; border-color: #dbeafe; }
.comment-bubble::after { content: ''; position: absolute; left: -8px; top: 15px; border-width: 8px 8px 8px 0; border-style: solid; border-color: transparent #e2e8f0 transparent transparent; }
.comment-bubble.admin::after { border-color: transparent #dbeafe transparent transparent; }

/* Footer */
footer { flex-shrink: 0; background: #fff; border-top: 1px solid var(--border); padding: 0.75rem 0; }

/* Utilities & Components */
.metric { background: #fff; padding: 1rem; border-radius: 12px; border: 1px solid var(--border); display: flex; flex-direction: column; }
.metric span { font-size: 0.6rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 0.25rem; }
.metric strong { font-size: 1.25rem; }

.badge-erp { padding: 0.4rem 0.8rem; border-radius: 6px; font-weight: 600; font-size: 0.7rem; display: inline-flex; align-items: center; }
.badge-urgent { background: #fef2f2; color: #991b1b; }
.badge-high { background: #fff7ed; color: #9a3412; }
.badge-normal { background: #f0fdf4; color: #166534; }
.badge-low { background: #f8fafc; color: #475569; }

.badge-open { background: #fee2e2; color: #991b1b; }
.badge-progress { background: #eff6ff; color: #1e40af; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-closed { background: #f1f5f9; color: #475569; }

.preline { white-space: pre-line; }

/* Pagination Styles */
.pagination-footer {
  padding: 1rem 1.5rem;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.pagination-btn {
  height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0 0.75rem;
  transition: all 0.2s;
  text-decoration: none;
}

.pagination-btn:hover:not(.disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-subtle);
}

.pagination-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f8fafc;
}

.pagination-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Login Page Styles */
.login-wrapper {
  min-height: calc(100vh - var(--nav-height) - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, #eff6ff, transparent),
              radial-gradient(circle at bottom left, #f8fafc, transparent);
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  padding: 2.5rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
  transition: transform 0.3s ease;
}

.login-card:hover {
  transform: translateY(-4px);
}

.login-card .btn-primary {
  height: 48px;
  font-weight: 600;
  border-radius: 10px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.login-card .btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.login-card .form-control {
  height: 46px;
  border-radius: 10px;
}

.login-card .input-group-text {
  border-radius: 10px 0 0 10px;
}

@media (max-width: 1200px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { flex-wrap: wrap; }
}
