/* ==========================================================
   TG Explorer — "Studio" Light SaaS Design
   Bright, clean, professional. Plus Jakarta Sans + Instrument Serif.
   ========================================================== */

/* --- Tokens --- */
:root {
  --bg:            #F5F4F1;
  --bg-page:       #F5F4F1;
  --surface:       #FFFFFF;
  --surface-hover: #FAFAF8;
  --surface-alt:   #F9F9F7;

  --border:        #E6E5E1;
  --border-light:  #EEEDE9;
  --border-focus:  #2F6FEB;

  --text:          #1C1C1A;
  --text-2:        #64635F;
  --text-3:        #9D9C98;
  --text-4:        #C4C3BF;

  --primary:       #2F6FEB;
  --primary-hover: #2560D4;
  --primary-soft:  rgba(47, 111, 235, 0.07);
  --primary-text:  #2F6FEB;

  --red:           #DC4A43;
  --red-soft:      rgba(220, 74, 67, 0.08);
  --green:         #1A9A5C;
  --green-soft:    rgba(26, 154, 92, 0.07);
  --amber:         #D4850D;
  --amber-soft:    rgba(212, 133, 13, 0.07);
  --purple:        #7C5CFC;
  --purple-soft:   rgba(124, 92, 252, 0.07);
  --pink:          #D44B8A;
  --pink-soft:     rgba(212, 75, 138, 0.07);
  --cyan:          #0E8A8A;
  --cyan-soft:     rgba(14, 138, 138, 0.07);
  --blue:          #3B82F6;
  --blue-soft:     rgba(59, 130, 246, 0.07);
  --gray:          #71706C;
  --gray-soft:     rgba(113, 112, 108, 0.07);
  --orange:        #C97416;
  --orange-soft:   rgba(201, 116, 22, 0.07);

  --serif:         'Instrument Serif', Georgia, serif;
  --sans:          'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --mono:          'IBM Plex Mono', 'SFMono-Regular', monospace;

  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     14px;

  --shadow-xs:     0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg:     0 8px 28px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);

  --transition:    160ms ease;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--sans);
  background: var(--bg-page);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

::selection {
  background: var(--primary-soft);
  color: var(--primary);
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--border-light);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.wordmark {
  font-family: var(--serif);
  font-weight: 400;
  font-style: italic;
  font-size: 1.4rem;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.01em;
}

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.header-count {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--primary-text);
}

.header-count-label {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-left: -6px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-import {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(47, 111, 235, 0.22), 0 0 0 1px rgba(47, 111, 235, 0.12);
  transition: all var(--transition);
}
.btn-import:hover {
  background: var(--primary-hover);
  box-shadow: 0 3px 8px rgba(47, 111, 235, 0.28), 0 0 0 1px rgba(47, 111, 235, 0.15);
  transform: translateY(-1px);
}
.btn-import:active { transform: translateY(0); }
.btn-import-icon {
  font-size: 1.15rem;
  line-height: 1;
  font-weight: 300;
}

.btn-clear {
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-xs);
}
.btn-clear:hover {
  background: var(--surface-hover);
  border-color: var(--border);
  color: var(--text);
}

.btn-delete {
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-delete:hover {
  background: var(--red-soft);
  border-color: rgba(220, 74, 67, 0.18);
}

/* ============================================================
   MAIN
   ============================================================ */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px 80px;
}

/* ============================================================
   STATS ROW
   ============================================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: all 200ms ease;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2.5px;
  background: var(--stat-color, var(--primary));
  opacity: 0.55;
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-top: 4px;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-4);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.search-field-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-4);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.85rem;
  outline: none;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}
.search-field input::placeholder { color: var(--text-4); }
.search-field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-xs);
}

.toolbar-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-dropdown {
  padding: 9px 30px 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  box-shadow: var(--shadow-xs);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%239D9C98' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: all var(--transition);
}
.filter-dropdown:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-xs);
}
.filter-dropdown option { background: var(--surface); color: var(--text); }

/* ============================================================
   TABLE
   ============================================================ */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead { background: var(--surface-alt); }

.table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.th-sort { cursor: pointer; transition: color var(--transition); position: relative; }
.th-sort:hover { color: var(--text-2); }
.th-sort.active { color: var(--primary-text); }
.th-sort::after {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  margin-left: 5px;
  vertical-align: middle;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid var(--text-4);
  opacity: 0;
  transition: opacity var(--transition);
}
.th-sort:hover::after { opacity: 0.5; }
.th-sort.active::after { opacity: 1; border-top-color: var(--primary); }
.th-sort.asc.active::after {
  border-top: none;
  border-bottom: 4px solid var(--primary);
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.85rem;
  vertical-align: top;
}

.table tbody tr {
  transition: background 120ms ease;
  cursor: pointer;
}
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: none; }

/* Column widths */
.col-id    { width: 52px; }
.col-chat  { width: 120px; }
.col-sender{ width: 140px; }
.col-cat   { width: 115px; }
.col-date  { width: 130px; }
.col-time  { width: 60px; }

/* Cell styles */
.cell-id {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-4);
}

.cell-chat {
  color: var(--text-2);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.cell-sender {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
}

.sender-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--surface);
}

/* Category pill — SaaS style */
.cell-cat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Category colors */
.cat-c-RDP       { background: var(--pink); }
.cat-c-Error     { background: var(--red); }
.cat-c-Warning   { background: var(--amber); }
.cat-c-SSH       { background: var(--cyan); }
.cat-c-Login     { background: var(--purple); }
.cat-c-Monitoring{ background: var(--green); }
.cat-c-Backup    { background: var(--blue); }
.cat-c-Security  { background: var(--orange); }
.cat-c-Updates   { background: var(--purple); }
.cat-c-System    { background: var(--gray); }
.cat-c-General   { background: var(--text-4); }

.cat-pill-RDP       { background: var(--pink-soft);   color: var(--pink); }
.cat-pill-Error     { background: var(--red-soft);    color: var(--red); }
.cat-pill-Warning   { background: var(--amber-soft);  color: var(--amber); }
.cat-pill-SSH       { background: var(--cyan-soft);   color: var(--cyan); }
.cat-pill-Login     { background: var(--purple-soft); color: var(--purple); }
.cat-pill-Monitoring{ background: var(--green-soft);  color: var(--green); }
.cat-pill-Backup    { background: var(--blue-soft);   color: var(--blue); }
.cat-pill-Security  { background: var(--orange-soft); color: var(--orange); }
.cat-pill-Updates   { background: var(--purple-soft); color: var(--purple); }
.cat-pill-System    { background: var(--gray-soft);   color: var(--gray); }
.cat-pill-General   { background: var(--gray-soft);   color: var(--text-3); }

.cell-message {
  max-width: 420px;
  color: var(--text-2);
  font-size: 0.82rem;
  line-height: 1.50;
}

.msg-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.cell-date,
.cell-time {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
}

/* Empty State */
.empty {
  padding: 80px 20px;
  text-align: center;
}

.empty-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--text-3);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--text-4);
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  gap: 12px;
}

.pagination-info {
  font-size: 0.78rem;
  color: var(--text-3);
  font-family: var(--mono);
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 3px;
}

.pg-btn {
  min-width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.78rem;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}
.pg-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border);
  color: var(--text);
}
.pg-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 1px 4px rgba(47, 111, 235, 0.25);
}
.pg-btn:disabled { opacity: 0.3; cursor: default; }

.pg-ellipsis {
  padding: 0 4px;
  color: var(--text-4);
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ============================================================
   MODAL OVERLAY
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(28, 28, 26, 0.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.overlay.active { opacity: 1; pointer-events: auto; }

.modal {
  width: 92%;
  max-width: 520px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(8px) scale(0.98);
  transition: transform 220ms ease;
}
.overlay.active .modal { transform: translateY(0) scale(1); }
.modal-wide { max-width: 660px; }

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

.modal-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-x {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.modal-x:hover { background: var(--surface-alt); color: var(--text); }

.modal-content {
  padding: 24px;
  overflow-y: auto;
}

/* ============================================================
   DROPZONE
   ============================================================ */
.dropzone {
  padding: 56px 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-label {
  font-size: 0.88rem;
  color: var(--text-3);
}
.dropzone-label code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--text-2);
}
.dropzone-label u {
  color: var(--primary-text);
  text-underline-offset: 2px;
}

/* Progress */
.upload-progress { margin-top: 20px; }
.progress-track {
  height: 4px;
  background: var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 300ms ease;
  border-radius: 4px;
}
.progress-label {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-3);
  text-align: center;
}

/* Upload Result */
.upload-result {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.65;
}
.upload-result.success {
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid rgba(26, 154, 92, 0.12);
}
.upload-result.error {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid rgba(220, 74, 67, 0.12);
}

/* Import History */
.modal-imports {
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border-light);
  max-height: 230px;
  overflow-y: auto;
}
.modal-imports-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
}

.import-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}
.import-row:last-child { border-bottom: none; }

.import-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.import-meta {
  font-size: 0.7rem;
  color: var(--text-4);
  font-family: var(--mono);
}

/* ============================================================
   DETAIL MODAL
   ============================================================ */
.detail-row {
  display: flex;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 16px;
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  width: 80px;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding-top: 3px;
}

.detail-value {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.65;
  min-width: 0;
  flex: 1;
}

.detail-value code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--primary-text);
}

.detail-body {
  padding: 18px 20px;
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--text-2);
}
.detail-body strong { color: var(--text); font-weight: 600; }
.detail-body code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border-light);
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--primary-text);
}

/* Upload File List (multi-file breakdown) */
.upload-files-list {
  margin-top: 12px;
  border-top: 1px solid rgba(26, 154, 92, 0.12);
  padding-top: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.upload-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.78rem;
}

.upload-file-icon {
  width: 18px;
  flex-shrink: 0;
  font-weight: 700;
  text-align: center;
}

.upload-file-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: 0.72rem;
}

.upload-file-count {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  opacity: 0.7;
}

.upload-file-error {
  color: var(--red);
}

.dropzone-sub {
  font-size: 0.75rem;
  color: var(--text-4);
  margin-top: 6px;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes rowIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row-enter {
  animation: rowIn 180ms ease forwards;
  opacity: 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .header { padding: 0 16px; }
  .main { padding: 20px 16px 48px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .col-id, .col-chat { display: none; }
  .toolbar { flex-direction: column; }
  .search-field { min-width: 100%; }
  .toolbar-filters { width: 100%; flex-wrap: wrap; }
  .filter-dropdown { flex: 1; min-width: 0; }
  .cell-message { max-width: 180px; }
}

@media (max-width: 540px) {
  .stats-row { grid-template-columns: 1fr; }
  .col-sender { display: none; }
  .pagination { flex-direction: column; text-align: center; }
}
