:root {
  --bg: #0f1117;
  --bg2: #161b22;
  --bg3: #1c2230;
  --bg4: #21262d;
  --border: #30363d;
  --accent: #238636;
  --accent2: #2ea043;
  --blue: #1f6feb;
  --blue2: #388bfd;
  --re: #f85149;
  --ye: #d29922;
  --t1: #f0f6fc;
  --t2: #c9d1d9;
  --t3: #8b949e;
  --t4: #484f58;
  --radius: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--t1); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; }
a { cursor: pointer; text-decoration: none; }

/* NAVBAR */
.navbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 10px; margin-right: 16px; }
.nav-logo { font-size: 22px; }
.nav-title { font-size: 16px; font-weight: 700; color: var(--t1); white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
  color: var(--t3); padding: 6px 14px; border-radius: var(--radius);
  font-size: 13px; transition: all .15s; white-space: nowrap;
}
.nav-link:hover { color: var(--t1); background: var(--bg3); }
.nav-link.active { color: var(--t1); background: var(--bg4); font-weight: 600; }

/* CONTAINER */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }
.page { display: none; }
.page.active { display: block; }

/* SECTION HEADERS */
.section-title { font-size: 22px; font-weight: 700; color: var(--t1); margin-bottom: 4px; }
.section-sub { color: var(--t3); font-size: 13px; margin-bottom: 20px; }

/* CARDS */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--t2); margin-bottom: 16px; }

/* STATS GRID */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; text-align: center;
  border-left: 3px solid var(--border);
}
.stat-card.blue { border-left-color: var(--blue); }
.stat-card.accent { border-left-color: var(--accent); }
.stat-card.red { border-left-color: var(--re); }
.stat-card.yellow { border-left-color: var(--ye); }
.stat-value { font-size: 28px; font-weight: 800; color: var(--t1); line-height: 1; }
.stat-label { font-size: 11px; color: var(--t3); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }

/* TOOLBAR */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.search-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  color: var(--t1); border-radius: var(--radius); padding: 8px 14px; font-size: 13px;
}
.search-input:focus { outline: none; border-color: var(--blue); }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); font-size: 13px;
  font-weight: 600; border: none; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue2); }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--accent2); }
.btn-secondary { background: var(--bg4); color: var(--t2); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg3); color: var(--t1); }
.btn-danger { background: transparent; color: var(--re); border: 1px solid var(--re); }
.btn-danger:hover:not(:disabled) { background: rgba(248,81,73,.15); }
.btn-ghost { background: transparent; color: var(--t3); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--t1); border-color: var(--t3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* TABLE */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--bg3); color: var(--t3); font-size: 11px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--t2); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-new { background: rgba(31,111,235,.2); color: var(--blue2); }
.badge-processing { background: rgba(210,153,34,.2); color: var(--ye); }
.badge-ready { background: rgba(35,134,54,.2); color: #56d364; }
.badge-sent { background: rgba(35,134,54,.15); color: #3fb950; }
.badge-error { background: rgba(248,81,73,.2); color: var(--re); }
.badge-draft { background: var(--bg4); color: var(--t3); }
.badge-feasr { background: rgba(56,139,253,.15); color: var(--blue2); }
.badge-pnrr { background: rgba(210,153,34,.15); color: var(--ye); }
.badge-du { background: rgba(139,148,158,.15); color: var(--t3); }
.badge-rrv { background: rgba(123,31,162,.2); color: #ce93d8; }

/* MODALS */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 780px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--t1); }
.btn-close {
  background: none; border: none; color: var(--t3);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.btn-close:hover { color: var(--t1); background: var(--bg4); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* PROGRESS */
.progress-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--t2); font-size: 13px; }
.progress-wrap { background: var(--bg4); border-radius: 20px; height: 8px; overflow: hidden; margin-bottom: 16px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--blue), var(--accent)); border-radius: 20px; transition: width .4s ease; width: 0%; }
.progress-logs {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; max-height: 300px;
  overflow-y: auto; font-family: monospace; font-size: 12px;
}
.log-entry { display: flex; gap: 10px; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log-entry:last-child { border-bottom: none; }
.log-time { color: var(--t4); white-space: nowrap; }
.log-info { color: var(--t3); }
.log-warning { color: var(--ye); }
.log-error { color: var(--re); }
.log-debug { color: var(--t4); }

/* EMAIL CARDS */
.send-summary {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; margin-bottom: 12px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--t2);
}
.email-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
  transition: border-color .15s;
}
.email-card.selected { border-color: var(--blue); }
.email-card-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer;
}
.email-card-header:hover { background: var(--bg4); }
.email-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue); }
.email-coord-name { font-weight: 600; color: var(--t1); flex: 1; }
.email-stats { font-size: 12px; color: var(--t3); }
.email-card-body { padding: 14px; border-top: 1px solid var(--border); display: none; }
.email-card-body.open { display: block; }

/* FORMS */
.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 11px; font-weight: 600; color: var(--t3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.form-input, .form-textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  color: var(--t1); border-radius: var(--radius); padding: 8px 12px; font-size: 13px;
  font-family: inherit;
}
.form-textarea { resize: vertical; min-height: 120px; }
.form-input:focus, .form-textarea:focus { outline: none; border-color: var(--blue); }
.attachment-info {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px; font-size: 12px; color: var(--t3);
}
.attachment-download {
  display: flex; align-items: center; gap: 8px;
  color: var(--blue); text-decoration: none; font-weight: 500;
  flex: 1; transition: color .2s;
}
.attachment-download:hover { color: var(--t1); text-decoration: underline; }
.dl-badge {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--blue); color: #fff; border-radius: 4px;
  padding: 2px 8px; font-size: 11px; font-weight: 600;
  white-space: nowrap; margin-left: 4px;
}
.attachment-download:hover .dl-badge { background: var(--t1); }


/* LOADER */
.loader {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; color: var(--t3); font-size: 13px;
}
.loader::before {
  content: ''; width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .7s linear infinite; margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-sm {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.loading-text { color: var(--t3); text-align: center; padding: 20px; font-size: 13px; }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 48px 20px; }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--t2); margin-bottom: 6px; }
.empty-text { font-size: 13px; color: var(--t3); }

/* TOAST */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  box-shadow: var(--shadow); min-width: 280px; max-width: 380px;
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { border-left: 3px solid var(--accent); }
.toast-error { border-left: 3px solid var(--re); }
.toast-warning { border-left: 3px solid var(--ye); }
.toast-info { border-left: 3px solid var(--blue); }
.toast-icon { font-size: 16px; margin-top: 1px; }
.toast-success .toast-icon { color: var(--accent2); }
.toast-error .toast-icon { color: var(--re); }
.toast-warning .toast-icon { color: var(--ye); }
.toast-info .toast-icon { color: var(--blue2); }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; color: var(--t1); font-size: 13px; }
.toast-msg { color: var(--t3); font-size: 12px; margin-top: 2px; }

/* HIDDEN */
.hidden { display: none !important; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--t4); }

@media (max-width: 768px) {
  .navbar { padding: 0 12px; }
  .nav-title { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .data-table th:nth-child(3), .data-table td:nth-child(3) { display: none; }
  .modal { max-width: 100%; margin: 0; border-radius: 10px 10px 0 0; align-self: flex-end; max-height: 95vh; }
  .modal-overlay { align-items: flex-end; }
}
