/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --blue:      #2563eb;
  --blue-dark: #1d4ed8;
  --red:       #dc2626;
  --amber:     #d97706;
  --green:     #16a34a;
  --gray-50:   #f8fafc;
  --gray-100:  #f1f5f9;
  --gray-200:  #e2e8f0;
  --gray-400:  #94a3b8;
  --gray-600:  #475569;
  --gray-700:  #334155;
  --gray-900:  #0f172a;
  --radius:    6px;
  --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--gray-900); background: var(--gray-50); }
a { color: var(--blue); text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: 14px; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 500; transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-100); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.text-danger { color: var(--red) !important; }

/* ── Form Elements ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 5px; color: var(--gray-700); font-size: 13px; }
input[type=text], input[type=password], input[type=email], textarea, select {
  width: 100%; padding: 8px 11px; border: 1px solid var(--gray-200); border-radius: var(--radius);
  background: white; color: var(--gray-900); outline: none; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { resize: vertical; min-height: 100px; }
.error-msg { color: var(--red); font-size: 13px; padding: 8px 12px; background: #fef2f2; border-radius: var(--radius); margin-bottom: 12px; }

/* ── Login Page ──────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--gray-100); }
.login-card { width: 360px; background: white; border-radius: 12px; padding: 36px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; font-size: 18px; font-weight: 700; color: var(--gray-900); }
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--gray-400); margin-bottom: 24px; font-size: 13px; }

/* ── App Layout ──────────────────────────────────────────────────────────── */
.app-page { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px; background: white; border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.header-right { display: flex; align-items: center; gap: 12px; }
.sync-status { font-size: 12px; color: var(--gray-400); }

/* User menu */
.user-menu { position: relative; }
#userLabel {
  font-weight: 600; color: var(--gray-700); cursor: pointer; padding: 5px 10px;
  border-radius: var(--radius); border: 1px solid var(--gray-200); background: var(--gray-50);
  user-select: none;
}
#userLabel:hover { background: var(--gray-100); }
.user-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: white; border: 1px solid var(--gray-200); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 160px; z-index: 200;
}
.user-dropdown.open { display: block; }
.user-dropdown button {
  display: block; width: 100%; padding: 9px 14px; text-align: left;
  background: none; border: none; color: var(--gray-700);
}
.user-dropdown button:hover { background: var(--gray-100); }

/* Stats bar */
.stats-bar {
  display: flex; gap: 0; background: white; border-bottom: 1px solid var(--gray-200);
}
.stat {
  flex: 1; padding: 12px 20px; text-align: center; cursor: pointer;
  border-right: 1px solid var(--gray-200); transition: background .15s;
}
.stat:last-child { border-right: none; }
.stat:hover { background: var(--gray-50); }
.stat-num { display: block; font-size: 24px; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: .5px; }
.stat-missing .stat-num { color: var(--red); }
.stat-investigating .stat-num { color: var(--amber); }
.stat-resolved .stat-num { color: var(--green); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: white; border-bottom: 1px solid var(--gray-200);
}
.filter-tabs { display: flex; gap: 4px; }
.tab {
  padding: 6px 14px; border-radius: var(--radius); border: 1px solid transparent;
  background: none; color: var(--gray-600); font-size: 13px; transition: all .15s;
}
.tab:hover { background: var(--gray-100); color: var(--gray-900); }
.tab.active { background: var(--blue); color: white; border-color: var(--blue); }
.search-wrap input {
  width: 260px; padding: 6px 12px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); background: var(--gray-50);
}

/* Table */
.table-wrap { flex: 1; overflow-x: auto; padding: 16px 20px; }
.cases-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.cases-table th {
  padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; color: var(--gray-600);
  background: var(--gray-50); border-bottom: 1px solid var(--gray-200);
}
.cases-table td { padding: 11px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.cases-table tr:last-child td { border-bottom: none; }
.cases-table tbody tr:hover { background: #f0f7ff; cursor: pointer; }
.cases-table .title-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-row { text-align: center; color: var(--gray-400); padding: 40px !important; }

/* Status badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 500;
}
.badge-missing { background: #fef2f2; color: #b91c1c; }
.badge-investigating { background: #fffbeb; color: #92400e; }
.badge-resolved { background: #f0fdf4; color: #15803d; }

/* ── Detail Panel ────────────────────────────────────────────────────────── */
.detail-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3);
  z-index: 150;
}
.detail-panel {
  position: fixed; top: 0; right: -105vw; width: min(1180px, calc(100vw - 20px)); height: 100vh;
  background: white; box-shadow: var(--shadow-lg); z-index: 160;
  overflow-y: auto; transition: right .3s ease;
}
.detail-panel.open { right: 0; }
.detail-overlay.open { display: block; }
.detail-inner { padding: 28px 32px; }

.detail-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 12px; }
.detail-header h2 { font-size: 20px; font-weight: 700; line-height: 1.3; }
.close-btn { background: none; border: none; font-size: 20px; color: var(--gray-400); padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.close-btn:hover { background: var(--gray-100); color: var(--gray-700); }

.detail-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 20px; margin-bottom: 20px; }
.meta-item label { font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: .4px; display: block; }
.meta-item span { font-weight: 500; font-size: 14px; }

.detail-notes-header { font-size: 13px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px; padding-top: 22px; border-top: 1px solid var(--gray-200); }
.investigation-notes { background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; color: #78350f; margin-bottom: 16px; }

.action-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; padding: 16px; background: var(--gray-50); border-radius: var(--radius); border: 1px solid var(--gray-200); }
.action-bar .btn { padding: 9px 18px; font-size: 14px; font-weight: 500; }

.timeline { margin-bottom: 20px; }
.timeline-item { display: flex; gap: 10px; margin-bottom: 12px; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray-400); flex-shrink: 0; margin-top: 5px; }
.timeline-content { flex: 1; }
.timeline-meta { font-size: 13px; color: var(--gray-500); margin-bottom: 4px; font-weight: 500; }
.timeline-text { font-size: 15px; color: var(--gray-800); line-height: 1.5; }
.timeline-item.note .timeline-dot  { background: var(--blue); }
.timeline-item.email .timeline-dot  { background: var(--green); }
.timeline-item.reply .timeline-dot  { background: var(--amber); }

.email-item { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.email-item-meta { font-size: 11px; color: var(--gray-400); margin-bottom: 4px; }
.email-item-subject { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.email-body-preview { font-size: 12px; color: var(--gray-600); white-space: pre-wrap; max-height: 80px; overflow: hidden; }
.email-body-preview.expanded { max-height: none; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: white; border-radius: 10px; padding: 28px; width: 520px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.modal-box .modal-sub { font-size: 13px; color: var(--gray-400); margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--gray-200); }

/* Resolution select */
.resolution-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.resolution-opt {
  padding: 12px 14px; border: 2px solid var(--gray-200); border-radius: var(--radius);
  cursor: pointer; text-align: center; font-weight: 500; transition: all .15s;
}
.resolution-opt:hover { border-color: var(--blue); color: var(--blue); }
.resolution-opt.selected { border-color: var(--blue); background: #eff6ff; color: var(--blue); }

/* Admin panel */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--gray-200); }
.users-table th { font-size: 12px; color: var(--gray-600); }
.role-badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; font-weight: 500; }
.role-admin { background: #eff6ff; color: var(--blue); }
.role-va    { background: var(--gray-100); color: var(--gray-600); }

/* Notification badge */
.notif-btn { position: relative; background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 5px 10px; cursor: pointer; font-size: 16px; }
.notif-btn:hover { background: var(--gray-100); }
.notif-badge { position: absolute; top: -5px; right: -5px; background: var(--red); color: white; border-radius: 99px; font-size: 10px; font-weight: 700; padding: 1px 5px; min-width: 16px; text-align: center; line-height: 14px; }
.notif-dropdown { display: none; position: absolute; right: 0; top: calc(100% + 6px); width: 340px; background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 300; }
.notif-dropdown.open { display: block; }
.notif-header { padding: 10px 14px; border-bottom: 1px solid var(--gray-200); font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); cursor: pointer; }
.notif-item:hover { background: var(--gray-50); }
.notif-item.unread { background: #eff6ff; }
.notif-item-text { font-size: 13px; color: var(--gray-700); }
.notif-item-time { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.notif-empty { padding: 20px; text-align: center; color: var(--gray-400); font-size: 13px; }

/* Line items table in detail panel */
.line-items-wrap { overflow-x: auto; margin-bottom: 16px; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.line-items-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 700px; }
.line-items-table th { padding: 11px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .4px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
.line-items-table td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.line-items-table tr:last-child td { border-bottom: none; }
.line-items-table .col-title  { min-width: 260px; max-width: 380px; }
.line-items-table .col-asin   { width: 100px; }
.line-items-table .col-msku   { min-width: 130px; max-width: 180px; }
.line-items-table .col-cost   { width: 75px; white-space: nowrap; }
.line-items-table .col-qty    { width: 45px; text-align: center; }
.line-items-table .col-status { width: 130px; }
.line-items-table .col-action { width: 110px; }
.line-items-table .col-action .btn { display: block; width: 100%; margin-bottom: 4px; font-size: 12px; padding: 5px 8px; text-align: center; }
.line-items-table .col-action .btn:last-child { margin-bottom: 0; }
.cell-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.cell-wrap { white-space: normal; word-break: break-word; display: block; line-height: 1.35; }

/* Sortable headers */
th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sort]:hover { background: var(--gray-100); }
th.sort-active { color: var(--blue); }
.sort-ind { font-size: 11px; color: var(--gray-400); }
th.sort-active .sort-ind { color: var(--blue); }

/* Email threads */
.email-thread-group { border: 1px solid var(--gray-200); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.email-thread-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--gray-500); padding: 9px 14px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
.email-thread-msg { padding: 12px 14px; }
.email-sent { background: white; }
.email-received { background: #f0fdf4; border-left: 4px solid #16a34a; }
.email-thread-meta { font-size: 13px; color: var(--gray-500); margin-bottom: 6px; font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.email-reply-badge { display: inline-block; background: #16a34a; color: white; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.email-sent-badge { display: inline-block; background: var(--gray-400); color: white; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.email-from-addr { font-size: 13px; font-weight: 600; color: #15803d; }
.email-thread-subject { font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--gray-500); }
.email-thread-body { font-size: 14px; color: var(--gray-700); white-space: pre-wrap; max-height: 120px; overflow: hidden; }
.email-received .email-thread-body { max-height: none; }
.email-thread-body.expanded { max-height: none; }
.thread-action-btn { font-size: 11px; border: 1px solid var(--gray-200); background: white; color: var(--gray-600); border-radius: var(--radius); padding: 3px 8px; cursor: pointer; }
.thread-action-btn:hover { background: var(--gray-100); color: var(--gray-900); }

/* Cost color tiers */
.cost-low  { color: #15803d; font-weight: 700; } /* green  — under $100  */
.cost-mid  { color: #b45309; font-weight: 700; } /* amber  — $100–$500  */
.cost-high { color: #b91c1c; font-weight: 700; } /* red    — over $500   */

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 99px; }
