* { box-sizing: border-box; }
:root {
  --bg: #0f1419;
  --panel: #1a2027;
  --panel-2: #232b35;
  --border: #2d3845;
  --text: #e8eef5;
  --text-dim: #8b97a7;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --priority: #ff5c5c;
  --new: #4f8cff;
  --approval: #2ecc71;
  --internal: #b97aff;
  --warning: #ffb347;
  --success: #2ecc71;
  --danger: #ff5c5c;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Header ===== */
header.top {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
.brand { font-size: 16px; font-weight: 600; }
.brand .mail-id { color: var(--text-dim); font-weight: 400; margin-left: 8px; font-size: 13px; }
.nav { display: flex; gap: 16px; }
.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-dim);
}
.nav a.active, .nav a:hover { background: var(--panel-2); color: var(--text); }
.toolbar { display: flex; gap: 8px; align-items: center; }
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  background: var(--bg);
  font-size: 12px;
  white-space: nowrap;
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-dim);
}
.sync-chip.ok .sync-dot { background: var(--success); }
.sync-chip.checking .sync-dot {
  background: var(--warning);
  animation: pulse 1s ease-in-out infinite;
}
.sync-chip.error .sync-dot { background: var(--danger); }
.sync-chip.off .sync-dot { background: var(--text-dim); }
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.success { background: transparent; color: var(--success); border-color: var(--success); }
.btn.warn { background: transparent; color: var(--warning); border-color: var(--warning); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--bg);
  font-size: 12px;
  white-space: nowrap;
}
.user-chip:empty { display: none; }

.email-actions .cat-select {
  width: auto;
  margin-bottom: 0;
  padding: 4px 8px;
  font-size: 12px;
  margin-left: auto;
}

/* ===== Attachments: photo gallery ===== */
.att-head { margin: 18px 0 10px; color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; }
.att-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.gal-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--bg);
}
.gal-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}
.gal-item:hover img { transform: scale(1.06); }
.gal-hover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.15s;
}
.gal-item:hover .gal-hover { opacity: 1; }

/* ===== Attachments: document tiles ===== */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.doc-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.doc-tile:hover { border-color: var(--accent); }
.doc-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: var(--text); }
.doc-icon {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
}
.doc-icon.pdf { background: #d9453d; }
.doc-icon.xls { background: #1e7e45; }
.doc-icon.doc { background: #2b65b5; }
.doc-icon.zip { background: #8a6d2f; }
.doc-icon.gen { background: #5a6675; }
.doc-info { display: flex; flex-direction: column; min-width: 0; }
.doc-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-size { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.doc-dl {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  font-size: 15px;
  background: var(--panel);
}
.doc-dl:hover { border-color: var(--accent); background: var(--panel-2); color: var(--accent-hover); }

/* ===== Image lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(5, 8, 12, 0.94);
  display: none;
  align-items: center;
  justify-content: center;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 6px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.6);
}
.lb-btn {
  position: absolute;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lb-btn:hover { background: rgba(255,255,255,0.2); }
.lb-close { top: 18px; right: 18px; font-size: 17px; }
.lb-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 18px; top: 50%; transform: translateY(-50%); }
.lb-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  color: #fff;
  font-size: 13px;
}
.lb-bar #lbName { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar #lbCount { color: rgba(255,255,255,0.6); }
@media (max-width: 600px) {
  .att-gallery { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .doc-grid { grid-template-columns: 1fr; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
}

/* ===== Quick navigation (sticky jump bar) ===== */
.quick-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 0;
  margin-bottom: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.quick-nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.quick-nav a:hover { background: var(--panel-2); border-color: var(--accent); color: var(--text); }
.qn-count {
  background: var(--bg);
  border-radius: 10px;
  padding: 0 7px;
  font-size: 11px;
  color: var(--text-dim);
}
/* keep section headings visible below the sticky bar when jumping */
.section { scroll-margin-top: 64px; }

.cat-tag {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

.status-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  text-transform: uppercase;
  background: var(--bg);
  border: 1px solid var(--border);
}
.status-chip.resolved { color: var(--success); border-color: var(--success); }
.status-chip.archived { color: var(--text-dim); }

/* ===== Layout ===== */
.container { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ===== Mail Sync ===== */
.sync-panel {
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.12), rgba(46, 204, 113, 0.08)), var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}
.sync-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.panel-kicker {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}
.sync-panel h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.2;
}
.sync-action {
  color: var(--text-dim);
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}
.sync-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.sync-grid > div {
  min-width: 0;
  background: rgba(15, 20, 25, 0.52);
  border: 1px solid rgba(45, 56, 69, 0.82);
  border-radius: 6px;
  padding: 10px;
}
.sync-grid span {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
}
.sync-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ===== Stats ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0; }
.stat-value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.stat.priority .stat-value { color: var(--priority); }
.stat.tasks .stat-value { color: var(--warning); }
.stat.clickable { cursor: pointer; user-select: none; transition: transform 0.1s, border-color 0.15s; }
.stat.clickable:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat.clickable.active { border-color: var(--accent); background: rgba(79,140,255,0.08); box-shadow: inset 0 0 0 1px var(--accent); }

/* ===== Category Sections ===== */
.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 20px;
  overflow: hidden;
}
.section-header {
  padding: 14px 20px;
  background: var(--panel-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.priority  { background: var(--priority); }
.dot.new       { background: var(--new); }
.dot.approval  { background: var(--approval); }
.dot.internal  { background: var(--internal); }
.dot.latest    { background: var(--warning); }
.dot.hold      { background: #ff8a3d; }
.dot.service   { background: #d65aff; }
.dot.sso       { background: #ffd166; }
.dot.revision  { background: #5bc0de; }
.dot.ack       { background: #6c7a89; }
.dot.cancel    { background: #888; }

.email-card.hold     { border-left: 3px solid #ff8a3d; }
.email-card.service  { border-left: 3px solid #d65aff; }
.email-card.sso      { border-left: 3px solid #ffd166; }
.email-card.new_order { border-left: 3px solid var(--new); }
.email-card.revision_hold    { border-left: 3px solid #ff8a3d; }
.email-card.costing_approval { border-left: 3px solid var(--approval); }
.email-card.others           { border-left: 3px solid var(--internal); }
.email-card.revision { border-left: 3px solid #5bc0de; }
.email-card.ack      { border-left: 3px solid #6c7a89; }
.email-card.cancel   { border-left: 3px solid #888; }
.email-card.latest   { border-left: 3px solid var(--warning); }

.latest-section .section-header { background: linear-gradient(135deg, rgba(255,179,71,0.18), rgba(46,204,113,0.05)); }
.priority-section .section-header { background: linear-gradient(135deg, rgba(255,92,92,0.18), rgba(255,92,92,0.05)); }

/* Gmail label chips on each card */
.label-row { margin: 4px 0 8px 0; display: flex; flex-wrap: wrap; gap: 4px; }
.label-chip {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px;
  background: rgba(79,140,255,0.18);
  border: 1px solid rgba(79,140,255,0.4);
  color: #b6d0ff;
  border-radius: 10px;
}
.count-badge {
  background: var(--bg);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

/* ===== Email cards ===== */
.email-list { padding: 8px; }
.email-card {
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid transparent;
  transition: all 0.15s;
}
.email-card:hover { background: var(--panel-2); border-color: var(--border); }
.email-card.priority { border-left: 3px solid var(--priority); }
.email-card.new       { border-left: 3px solid var(--new); }
.email-card.approval  { border-left: 3px solid var(--approval); }
.email-card.internal  { border-left: 3px solid var(--internal); }

.email-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.email-from { font-weight: 600; }
.email-time { color: var(--text-dim); font-size: 12px; }
.email-subject { font-size: 14px; margin-bottom: 6px; }
.email-summary { color: var(--text-dim); font-size: 13px; margin-bottom: 8px; }
.action-needed {
  background: rgba(255, 179, 71, 0.1);
  border-left: 2px solid var(--warning);
  padding: 6px 10px;
  margin: 8px 0;
  border-radius: 4px;
  font-size: 13px;
}
.action-needed b { color: var(--warning); }
.email-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ===== Empty state ===== */
.empty {
  padding: 30px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ===== Modal ===== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin: 0 0 16px 0; }
.modal-body { margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }
textarea, input[type="text"], input[type="date"], select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font: inherit;
  margin-bottom: 8px;
}
textarea { min-height: 120px; resize: vertical; font-family: inherit; }
label { display: block; color: var(--text-dim); font-size: 12px; margin: 6px 0 4px; text-transform: uppercase; letter-spacing: 0; }

/* ===== Logs / Tasks tables ===== */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}
th {
  background: var(--panel-2);
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0;
}
tr:hover td { background: var(--panel-2); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--bg);
}
.tag.reply         { color: var(--accent); }
.tag.resolved      { color: var(--success); }
.tag.archived      { color: var(--text-dim); }
.tag.task_created  { color: var(--warning); }
.tag.task_completed{ color: var(--success); }
.tag.priority      { color: var(--priority); }
.tag.category      { color: var(--internal); }

/* ===== Notification ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  padding: 12px 18px;
  border-radius: 6px;
  z-index: 200;
  display: none;
  max-width: 320px;
}
.toast.show { display: block; animation: slideIn 0.2s ease-out; }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

@media (max-width: 860px) {
  header.top {
    align-items: flex-start;
  }
  .brand,
  .nav,
  .toolbar {
    width: 100%;
  }
  .brand .mail-id {
    display: block;
    margin-left: 0;
    margin-top: 2px;
  }
  .nav {
    gap: 8px;
    overflow-x: auto;
  }
  .toolbar {
    justify-content: space-between;
  }
  .sync-summary {
    flex-direction: column;
  }
  .sync-action {
    text-align: left;
  }
  .sync-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .container {
    padding: 14px;
  }
  .sync-grid,
  .stats {
    grid-template-columns: 1fr;
  }
  .email-head {
    flex-direction: column;
    gap: 2px;
  }
  .email-actions .btn {
    flex: 1 1 120px;
  }
}
