/* Admin Panel Styles - Dark Theme (Current Admin Standard) */
/* Migrated from Admin App Example with current Admin styling */

:root {
  --bg: #141414;
  --panel: #1c1c1c;
  --panel-hover: #242424;
  --border: #262626;
  --border-light: #333333;
  --muted: #737373;
  --text: #d4d4d4;
  --text-bright: #f5f5f5;
  --primary: #22c55e;
  --primary-dark: #16a34a;
  --accent: #38bdf8;
  --danger: #ef4444;
  --warn: #f59e0b;
  --info: #3b82f6;
  --success: #22c55e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;

  /* Status Filter Colors (Soft) */
  --status-active: #60a5fa;
  --status-active-bg: rgba(96, 165, 250, 0.15);
  --status-active-border: rgba(96, 165, 250, 0.3);

  --status-pending: #fbbf24;
  --status-pending-bg: rgba(251, 191, 36, 0.15);
  --status-pending-border: rgba(251, 191, 36, 0.3);

  --status-completed: #4ade80;
  --status-completed-bg: rgba(74, 222, 128, 0.15);
  --status-completed-border: rgba(74, 222, 128, 0.3);

  --status-cancelled: #f87171;
  --status-cancelled-bg: rgba(248, 113, 113, 0.15);
  --status-cancelled-border: rgba(248, 113, 113, 0.3);

  --status-all: #a78bfa;
  --status-all-bg: rgba(167, 139, 250, 0.15);
  --status-all-border: rgba(167, 139, 250, 0.3);
}

/* Base Styles */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
  flex-shrink: 0;
}

.session-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Container */
.app-container {
  max-width: 1920px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* NEW: Tabs (from Example, adapted to current Admin colors) */
/* Tabs are now in the header, so style accordingly */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
}

.tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.tab.active {
  color: var(--text-bright);
  background: var(--panel-hover);
  border-color: var(--accent);
}

/* Panel & Card */
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.card h2 {
  margin: 0 0 20px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-bright);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.card h2 .title-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card h2 small {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

/* Status Filter Tabs (in card header) */
.status-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-filter-tab {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  transition: all 0.2s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-filter-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.status-filter-tab.active-status {
  background: var(--status-active-bg);
  border-color: var(--status-active-border);
  color: var(--status-active);
}

.status-filter-tab.pending-status {
  background: var(--status-pending-bg);
  border-color: var(--status-pending-border);
  color: var(--status-pending);
}

.status-filter-tab.completed-status {
  background: var(--status-completed-bg);
  border-color: var(--status-completed-border);
  color: var(--status-completed);
}

.status-filter-tab.cancelled-status {
  background: var(--status-cancelled-bg);
  border-color: var(--status-cancelled-border);
  color: var(--status-cancelled);
}

.status-filter-tab.all-status {
  background: var(--status-all-bg);
  border-color: var(--status-all-border);
  color: var(--status-all);
}

.status-filter-tab .count {
  font-size: 11px;
  opacity: 0.8;
}

.card .content {
  padding: 0;
}

/* Two-Pane Grid System */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  gap: 16px;
  margin-top: 14px;
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
}

/* When form pane is open: list=60%, form=40% */
.grid.split-view {
  grid-template-columns: 3fr 2fr;
}

#formCard {
  display: none;
}

.grid.split-view #formCard {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#listCard {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#listCard > .content,
.grid.split-view #formCard > .content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.tab-slot {
  min-height: 0;
}

/* Table card (rightCard) - first column */
#rightCard {
  /* Always visible */
}

/* Form card (leftCard) - second column, hidden by default */
#leftCard {
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.grid.split-view #leftCard {
  opacity: 1;
  pointer-events: auto;
}

.close-form-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  padding: 4px 8px;
  line-height: 1;
  transition: all 0.2s ease;
}

.close-form-btn:hover {
  color: var(--danger);
  background: var(--panel-hover);
  border-radius: 6px;
}

/* Smart Features: Duplicate warning and row highlight */
tr.duplicate-warning {
  background: rgba(251, 191, 36, 0.12) !important;
  border-left: 3px solid var(--warn);
}

tr.duplicate-warning td:first-child::before {
  content: '⚠️ ';
  margin-right: 4px;
}

tr.row-highlight {
  background: rgba(56, 189, 248, 0.15) !important;
  animation: pulse-highlight 2s ease-out;
}

@keyframes pulse-highlight {
  0%, 100% { background: rgba(56, 189, 248, 0.15); }
  50% { background: rgba(56, 189, 248, 0.3); }
}

/* Duplicate detection hint */
.duplicate-hint {
  display: none;
  padding: 8px 12px;
  background: rgba(251, 191, 36, 0.15);
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  font-size: 12px;
  color: var(--warn);
  margin-top: 8px;
}

.duplicate-hint.show {
  display: block;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* NEW: Filter Panel (enhanced toolbar) */
.filter-panel {
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}

.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-row:last-child {
  margin-bottom: 0;
}

.filter-group {
  flex: 1;
  min-width: 200px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  background: var(--panel-hover);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--border-light);
}

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

.btn.primary {
  background: var(--primary);
  color: #052e16;
}

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

/* NEW: Additional button variants */
.btn.danger {
  background: var(--danger);
  color: #fff;
}

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

.btn.good {
  background: var(--success);
  color: #052e16;
}

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

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

.btn.create-toggle {
  background: var(--accent);
  color: #0c4a6e;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn.create-toggle:hover {
  background: #0ea5e9;
}

.btn.create-toggle::before {
  content: '+';
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.btn-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 32px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.btn-close:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.btn-icon {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 16px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.btn-icon:hover {
  background: var(--panel-hover);
}

/* Inputs */
.input, select, textarea, input {
  background: #111111;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
  width: 100%;
}

.input:focus, select:focus, textarea:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.input::placeholder {
  color: var(--muted);
}

select {
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 80px;
  font-family: var(--sans);
  line-height: 1.5;
}

/* Checkbox Label */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  cursor: pointer;
}

/* NEW: Form Row (renamed from Example's .row to avoid conflict) */
.form-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* Override .row inside forms to use flexbox layout instead of grid */
.card .content .row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  grid-template-columns: unset;
  padding: 0;
  background: transparent;
  border: none;
  cursor: default;
}

.card .content .row:hover {
  background: transparent;
  border-color: transparent;
}

.card .content .row:focus {
  outline: none;
}

/* NEW: Column layout for forms */
.col {
  flex: 1;
  min-width: 320px;
}

/* NEW: Split layout */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* List/Table */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-header {
  display: grid;
  grid-template-columns: 100px 1fr 1fr 120px 120px 180px 180px 140px;
  gap: 12px;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.row {
  display: grid;
  grid-template-columns: 100px 1fr 1fr 120px 120px 180px 180px 140px;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #111111;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
  cursor: pointer;
}

.row:hover {
  background: var(--panel-hover);
  border-color: var(--border-light);
}

.row:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ticket-row {
  cursor: pointer;
}

.cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Table wrapper — horizontal scroll only; vertical scroll handled by parent .content */
.table-scroll-wrapper {
  overflow-x: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
}

.table-scroll-wrapper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-scroll-wrapper::-webkit-scrollbar-track {
  background: var(--panel);
  border-radius: 5px;
}

.table-scroll-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 5px;
}

.table-scroll-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.table-scroll-wrapper table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
}

/* NEW: Table styles for documents */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #111111;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: var(--panel-hover);
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--border-light);
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  gap: 6px;
}

/* Urgency Badges */
.badge.urgency-high {
  background: var(--danger);
  color: #fff;
}

.badge.urgency-medium {
  background: var(--warn);
  color: #1f2937;
}

.badge.urgency-low {
  background: var(--success);
  color: #052e16;
}

/* NEW: Urgency Score Display (more prominent) */
.urgency-score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 12px;
  border: 2px solid;
}

.urgency-score.high {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border-color: var(--danger);
}

.urgency-score.medium {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warn);
  border-color: var(--warn);
}

.urgency-score.low {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
  border-color: var(--info);
}

/* NEW: Aging Badge */
.aging-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.aging-badge.overdue {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.aging-badge.due-soon {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warn);
  border: 1px solid var(--warn);
}

.aging-badge.ok {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
  border: 1px solid var(--success);
}

/* Status Badges */
.badge.status-open {
  background: var(--info);
  color: #fff;
}

.badge.status-in_progress {
  background: var(--warn);
  color: #1f2937;
}

.badge.status-completed {
  background: var(--success);
  color: #052e16;
}

.badge.status-closed {
  background: var(--muted);
  color: #1f2937;
}

.badge.status-active {
  background: var(--success);
  color: #052e16;
}

/* Type Badges */
.badge.type-install {
  background: #3b82f6;
  color: #fff;
}

.badge.type-fault {
  background: #ef4444;
  color: #fff;
}

.badge.type-inspection {
  background: #8b5cf6;
  color: #fff;
}

.badge.type-coc {
  background: #f59e0b;
  color: #1f2937;
}

.badge.type-risk {
  background: #ec4899;
  color: #fff;
}

.badge.type-maintenance {
  background: #14b8a6;
  color: #fff;
}

/* Priority Badges */
.badge.priority-standard {
  background: var(--border-light);
  color: var(--text);
}

.badge.priority-medium {
  background: #3b82f6;
  color: #fff;
}

.badge.priority-high {
  background: var(--warn);
  color: #1f2937;
}

.badge.priority-premium {
  background: var(--danger);
  color: #fff;
}

/* Document Status Badges */
.badge.doc-status-not_started {
  background: var(--border-light);
  color: var(--muted);
}

.badge.doc-status-in_progress {
  background: var(--info);
  color: #fff;
}

.badge.doc-status-submitted {
  background: var(--warn);
  color: #1f2937;
}

.badge.doc-status-approved {
  background: var(--success);
  color: #052e16;
}

/* NEW: Document Badge (alternative smaller style) */
.doc-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.doc-badge.not-started {
  color: var(--muted);
}

.doc-badge.in-progress {
  color: var(--warn);
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}

.doc-badge.submitted {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
}

.doc-badge.approved {
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

.doc-status-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.chip.overdue {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.chip.aging {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warn);
  border: 1px solid var(--warn);
}

/* NEW: Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
  line-height: 1;
  color: var(--text-bright);
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Empty State */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* NEW: Document Modal Variants */
.modalShell {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
}

.modalToolbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.modalToolbar .left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.modalToolbar .left b {
  font-size: 12px;
  color: var(--text-bright);
}

.modalToolbar button {
  box-shadow: none;
}

.modalContent {
  padding: 20px;
}

/* NEW: Document Preview for Printing */
.docShell {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  color: #111;
  border-radius: 12px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.docToolbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  z-index: 10;
}

.docToolbar .left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.docToolbar .left b {
  font-size: 12px;
}

.docToolbar button {
  box-shadow: none;
}

.doc {
  padding: 40px 50px;
  font-family: var(--sans);
  background: #fff;
  color: #111;
  line-height: 1.6;
}

.doc h1 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.5px;
}

.doc .sub {
  color: #64748b;
  font-size: 13px;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 2px solid #e2e8f0;
}

.doc .bar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.doc .box {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 18px;
  min-width: 280px;
  flex: 1;
  background: #f8fafc;
}

.doc .box h3 {
  margin: 0 0 12px;
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.doc .kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  padding: 5px 0;
  border-bottom: 1px solid #f1f5f9;
}

.doc .kv:last-child {
  border-bottom: none;
}

.doc .kv span:first-child {
  color: #64748b;
  font-weight: 500;
}

.doc .kv span:last-child {
  color: #0f172a;
  font-weight: 500;
}

.doc table {
  margin-top: 24px;
  width: 100%;
  border-collapse: collapse;
}

.doc thead {
  background: #f1f5f9;
}

.doc th,
.doc td {
  border-bottom: 1px solid #e2e8f0;
  padding: 14px 12px;
  color: #0f172a;
  text-align: left;
}

.doc th {
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.doc td {
  font-size: 14px;
}

.doc tbody tr:hover {
  background: #f8fafc;
}

.doc .totals {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
}

.doc .totals .box {
  max-width: 400px;
  background: #0f172a;
  border-color: #0f172a;
}

.doc .totals .kv {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

.doc .totals .kv span {
  color: #e2e8f0 !important;
  font-size: 15px;
}

.doc .totals .kv:last-child span {
  font-size: 18px;
  font-weight: 700;
  color: #22c55e !important;
}

.doc .note {
  margin-top: 32px;
  padding: 16px;
  font-size: 13px;
  color: #475569;
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  border-radius: 4px;
}

.doc .footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* Form */
.form-section {
  margin-bottom: 24px;
}

.form-section:last-child {
  margin-bottom: 0;
}

.form-section h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
}

.form-group.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.hint {
  margin: 6px 0 0 0;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.new-client-section,
.inline-form {
  background: rgba(56, 189, 248, 0.05);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 8px;
  padding: 16px;
  margin-top: 12px;
}

.inline-form .row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  grid-template-columns: unset;
  padding: 0;
  background: transparent;
  border: none;
  cursor: default;
}

.inline-form .row:hover {
  background: transparent;
  border-color: transparent;
}

.inline-form h4 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-bright);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* NEW: Photo Upload Preview */
.photo-preview {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.photo-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Detail View */
.detail-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail-header,
.ticket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.detail-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--text-bright);
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.detail-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.detail-section,
.ticket-info-group {
  background: #111111;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.detail-section h3,
.ticket-info-group h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.ticket-info-group h3 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  margin-bottom: 14px;
  padding-bottom: 0;
  border-bottom: none;
}

.detail-grid,
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.detail-field,
.info-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-field label,
.info-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.info-label {
  font-size: 11px;
  letter-spacing: 0.4px;
}

.detail-field div,
.info-value {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.detail-field .muted {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.description {
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Documents */
.documents-list,
.document-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.document-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.document-section h3 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.document-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.document-item:hover {
  transform: translateX(4px);
  border-color: var(--accent);
}

.document-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.document-type,
.document-name {
  font-weight: 600;
  color: var(--text);
}

.document-name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.document-meta {
  font-size: 11px;
  color: var(--muted);
}

.document-actions {
  display: flex;
  gap: 4px;
}

/* Reports */
.reports-container {
  padding: 40px 20px;
  text-align: center;
}

.reports-container h2 {
  margin: 0 0 12px 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--text-bright);
}

/* Utility Classes */
.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
}

.tiny {
  font-size: 12px;
}

.right {
  text-align: right;
}

/* Notifications */
.notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  min-width: 300px;
  max-width: 500px;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.notification.show {
  transform: translateY(0);
  opacity: 1;
}

.notification-success {
  border-left: 4px solid var(--success);
}

.notification-error {
  border-left: 4px solid var(--danger);
}

.notification-info {
  border-left: 4px solid var(--info);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .list-header,
  .row {
    grid-template-columns: 90px 1fr 1fr 100px 100px 150px 150px 120px;
    gap: 8px;
    font-size: 13px;
  }
}

@media (max-width: 900px) {
  .app-header {
    flex-wrap: wrap;
  }

  .tabs {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px solid var(--border);
  }

  .list-header,
  .row {
    grid-template-columns: 80px 1fr 120px 140px;
    gap: 8px;
  }

  .list-header .cell:nth-child(3),
  .list-header .cell:nth-child(4),
  .list-header .cell:nth-child(8),
  .row .cell:nth-child(3),
  .row .cell:nth-child(4),
  .row .cell:nth-child(8) {
    display: none;
  }

  .detail-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    max-width: 100%;
  }

  .ticket-header {
    flex-direction: column;
  }

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

@media (max-width: 720px) {
  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .app-header {
    padding: 8px 12px;
  }

  .app-title {
    font-size: 16px;
  }

  .tabs {
    gap: 2px;
  }

  .tab {
    padding: 6px 12px;
    font-size: 12px;
  }

  .session-actions {
    gap: 4px;
  }

  .session-actions .btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .app-container {
    padding: 12px;
  }

  .panel,
  .card {
    padding: 16px;
  }

  .toolbar,
  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn,
  .toolbar .input,
  .toolbar select {
    width: 100%;
  }

  .list-header,
  .row {
    grid-template-columns: 1fr 120px;
    gap: 8px;
    padding: 10px 12px;
  }

  .list-header .cell:nth-child(n+3),
  .row .cell:nth-child(n+3) {
    display: none;
  }

  .list-header .cell:nth-child(6),
  .row .cell:nth-child(6) {
    display: flex;
  }

  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .detail-actions {
    width: 100%;
    justify-content: stretch;
  }

  .detail-actions .btn {
    flex: 1;
  }

  .notification {
    left: 20px;
    right: 20px;
    min-width: auto;
  }
}

/* Accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles */
@media print {
  /* Hide everything except the document */
  .app-header,
  .app-container,
  .toolbar,
  .tabs,
  .notification,
  .detail-actions,
  .docToolbar,
  .modalToolbar,
  .session-actions,
  #main-grid,
  #ticketModal {
    display: none !important;
  }

  /* Show only the document modal */
  #docModal {
    position: static !important;
    background: white !important;
    padding: 0 !important;
  }

  .docShell {
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .doc {
    padding: 20mm 15mm !important;
    max-width: 100% !important;
  }

  body {
    background: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Ensure proper page breaks */
  .doc table {
    page-break-inside: auto;
  }

  .doc tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  .doc thead {
    display: table-header-group;
  }

  /* Print-specific styling */
  .doc h1 {
    color: #000 !important;
  }

  .doc .box {
    border: 1px solid #ccc !important;
    background: white !important;
  }

  .doc .totals .box {
    background: #f5f5f5 !important;
    border: 1px solid #999 !important;
  }
}

/* ========================================
   CLIENT DETAIL VIEW - MASTER-DETAIL PATTERN
   ======================================== */

/* Selected row highlighting */
tr.client-row.selected {
  background: rgba(56, 189, 248, 0.15) !important;
  border-left: 3px solid var(--accent);
}

tr.client-row:hover {
  background: var(--panel-hover);
}

/* Client detail sections */
.client-detail-section {
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.client-detail-section:last-child {
  margin-bottom: 0;
}

.client-detail-header {
  padding: 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.client-detail-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
}

.client-detail-content {
  padding: 16px;
}

/* Collapsible sections */
.collapsible-section {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.collapsible-section:last-child {
  margin-bottom: 0;
}

.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--panel);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.collapsible-header:hover {
  background: var(--panel-hover);
}

.collapsible-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.collapsible-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  margin: 0;
}

.collapsible-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--accent);
  color: #0c4a6e;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.collapsible-toggle {
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.2s;
}

.collapsible-section.expanded .collapsible-toggle {
  transform: rotate(90deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.collapsible-section.expanded .collapsible-content {
  max-height: 1000px;
}

.collapsible-body {
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.related-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.2s;
}

.related-item:last-child {
  margin-bottom: 0;
}

.related-item:hover {
  background: var(--panel-hover);
}

.related-item-info {
  flex: 1;
}

.related-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 2px;
}

.related-item-meta {
  font-size: 11px;
  color: var(--muted);
}

.related-item-action {
  margin-left: 12px;
}

.view-all-link {
  display: block;
  margin-top: 12px;
  padding: 8px 12px;
  text-align: center;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}

.view-all-link:hover {
  background: rgba(56, 189, 248, 0.1);
}

.empty-related {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* =====================================================
   Light Mode Overrides — Slate Clean
   Applied when body.light-mode class is present
   ===================================================== */
body.light-mode {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-hover: #f1f5f9;
  --border: #d1d5db;
  --border-light: #9ca3af;
  --muted: #6b7280;
  --text: #374151;
  --text-bright: #111827;
  --accent: #0284c7;
}

body.light-mode .app-header {
  background: #c8cdd5;
  border-bottom-color: #b0b7c3;
}

body.light-mode input,
body.light-mode select,
body.light-mode textarea,
body.light-mode .input {
  background: #ffffff;
  color: #111827;
  border-color: #d1d5db;
}

body.light-mode input:focus,
body.light-mode select:focus,
body.light-mode textarea:focus,
body.light-mode .input:focus {
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

body.light-mode input:disabled,
body.light-mode select:disabled,
body.light-mode textarea:disabled {
  background: #f1f5f9;
  color: #6b7280;
}

body.light-mode .row {
  background: #ffffff;
  border-color: #d1d5db;
}

body.light-mode .row:hover {
  background: #f1f5f9;
  border-color: #9ca3af;
}

body.light-mode th {
  background: #c8cdd5;
  color: #374151;
}

body.light-mode tbody tr:hover {
  background: #f1f5f9;
}

body.light-mode .status-filter-tab {
  background: rgba(0, 0, 0, 0.04);
  color: #6b7280;
}

body.light-mode .status-filter-tab:hover {
  background: rgba(0, 0, 0, 0.07);
  color: #374151;
}

/* Settings modal additions */
.modal-sm { max-width:380px; }
.settings-row { display:flex; align-items:center; justify-content:space-between; padding:8px 0; }
.settings-row label { margin:0; font-weight:500; color:var(--text); }
.settings-btns { display:flex; gap:8px; }

/* ============================================================
   v3.1 PHASE 1 ADDITIONS
   ============================================================ */

/* Urgency badges — 5 levels */
.urgency-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.urgency-critical { background: #7f1d1d; color: #fecaca; border: 1px solid #dc2626; }
.urgency-high     { background: #7c2d12; color: #fed7aa; border: 1px solid #f97316; }
.urgency-elevated { background: #713f12; color: #fef08a; border: 1px solid #eab308; }
.urgency-standard { background: #1e3a5f; color: #bfdbfe; border: 1px solid #3b82f6; }
.urgency-low      { background: #1f2937; color: #9ca3af; border: 1px solid #4b5563; }

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.status-open       { background: rgba(59,130,246,.2); color: #93c5fd; border: 1px solid #3b82f6; }
.status-inprogress { background: rgba(245,158,11,.2); color: #fbbf24; border: 1px solid #d97706; }
.status-hold       { background: rgba(139,92,246,.2); color: #c4b5fd; border: 1px solid #8b5cf6; }
.status-closed     { background: rgba(34,197,94,.15); color: #86efac; border: 1px solid #16a34a; }
.status-cancelled  { background: rgba(107,114,128,.2); color: #9ca3af; border: 1px solid #4b5563; }

/* doc-badge additions — rejected state */
.doc-badge.rejected { color: var(--danger); border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.08); }

/* Table interaction */
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: rgba(255,255,255,.04); }
body.light-mode .clickable-row:hover { background: #f1f5f9; }
.row-selected { background: rgba(56,189,248,.08) !important; }
body.light-mode .row-selected { background: #e0f2fe !important; }

/* Loading row */
.loading-row { padding: 16px; text-align: center; }

/* Detail grid */
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .muted { font-size: 12px; color: var(--muted); }

/* Generic badge variants */
.badge-gray   { background: rgba(107,114,128,.2); color: #9ca3af; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-orange { background: rgba(245,158,11,.2);  color: #fbbf24; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-gold   { background: rgba(234,179,8,.2);   color: #facc15; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-red    { background: rgba(239,68,68,.2);   color: #fca5a5; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }

/* Error message in forms */
.error-msg {
  background: rgba(239,68,68,.12);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
}

/* Pagination */
.pagination { padding: 8px 0; }

/* Light mode urgency adjustments */
body.light-mode .urgency-critical { background: #fee2e2; color: #991b1b; }
body.light-mode .urgency-high     { background: #ffedd5; color: #9a3412; }
body.light-mode .urgency-elevated { background: #fef9c3; color: #854d0e; }
body.light-mode .urgency-standard { background: #dbeafe; color: #1e40af; }
body.light-mode .urgency-low      { background: #f3f4f6; color: #4b5563; }
body.light-mode .status-open       { background: #dbeafe; color: #1e40af; }
body.light-mode .status-inprogress { background: #fef3c7; color: #92400e; }
body.light-mode .status-hold       { background: #ede9fe; color: #5b21b6; }
body.light-mode .status-closed     { background: #dcfce7; color: #166534; }
body.light-mode .status-cancelled  { background: #f3f4f6; color: #374151; }
