* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #22252f;
  --border: #2a2d37;
  --text: #e4e4e7;
  --text-dim: #8b8d97;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --orange: #f97316;
  --blue: #3b82f6;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Login */
.view { min-height: 100vh; }

#dashboard-view {
  display: flex;
  height: 100vh;
}

.dashboard-left {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 360px;
}

.login-card h1 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 24px;
  color: var(--accent);
}

.login-card input {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover { background: var(--accent-hover); }

.error {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

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

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

.header-left h1 {
  font-size: 18px;
  color: var(--accent);
}

.header-right {
  display: flex;
  gap: 8px;
}

.manager-badge {
  background: var(--accent);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-danger { background: var(--red); }
.btn-danger:hover { background: #dc2626; }

.btn-success { background: var(--green); }
.btn-success:hover { background: #16a34a; }

.btn-warning { background: var(--orange); }
.btn-warning:hover { background: #ea580c; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: var(--bg-hover); }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  min-width: 80px;
}

.stat:hover { background: var(--bg-hover); }
.stat.active { background: var(--accent); }

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.stat.active .stat-label { color: rgba(255,255,255,0.8); }

/* Filters */
.filters {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-group select,
.filter-group input {
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-group input { flex: 1; max-width: 300px; }

.filter-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.filter-toggle-btn {
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.filter-toggle-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.filter-toggle-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.filter-toggle-btn.active {
  background: var(--accent);
  color: white;
}

/* Deals panel */
#deals-panel {
  padding: 0 24px;
}

/* Deals table */
#deals-table {
  width: 100%;
  border-collapse: collapse;
}

#deals-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

#deals-table td {
  padding: 12px 16px;
  font-size: 13px;
  vertical-align: middle;
}

#deals-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

#deals-table tbody tr:hover {
  background: var(--bg-hover);
}

#deals-table tbody tr.highlight {
  animation: highlight 2s ease-out;
}

@keyframes highlight {
  from { background: rgba(99, 102, 241, 0.3); }
  to { background: transparent; }
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-PAID { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.status-SENT { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.status-CONFIRMED { background: rgba(59, 130, 246, 0.2); color: var(--blue); }
.status-HAS_PROBLEM { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.status-ROLLED_BACK { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.status-FAILED { background: rgba(239, 68, 68, 0.1); color: #fca5a5; }
.status-PENDING { background: rgba(139, 141, 151, 0.2); color: var(--text-dim); }

/* Action buttons in table */
.actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.actions .btn { padding: 5px 14px; font-size: 13px; }

/* Empty / loading */
.empty-state, .loading {
  text-align: center;
  padding: 48px;
  color: var(--text-dim);
  font-size: 14px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

.pagination button {
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover { background: var(--bg-hover); }
.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Chat panel */
#chat-panel {
  width: 480px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-comment {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #1a1d27;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-msg.incoming {
  background: var(--bg);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.outgoing {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg .msg-meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

.chat-msg.outgoing .msg-meta { color: rgba(255,255,255,0.6); }

.chat-msg .msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.chat-msg.outgoing .msg-sender { color: rgba(255,255,255,0.8); }

.chat-msg.system-msg {
  align-self: center;
  max-width: 90%;
  background: rgba(139, 141, 151, 0.1);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  border-radius: 8px;
}
.chat-msg.system-msg.evt-green { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.chat-msg.system-msg.evt-yellow { background: rgba(234, 179, 8, 0.15); color: #facc15; }
.chat-msg.system-msg.evt-blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.chat-msg.system-msg.evt-red { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.chat-msg.system-msg.evt-orange { background: rgba(249, 115, 22, 0.15); color: #fb923c; }

.chat-img {
  max-width: 200px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.chat-img:hover { opacity: 0.85; }

.image-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.image-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 4px 30px rgba(0,0,0,0.5);
}

.chat-input-area {
  border-top: 1px solid var(--border);
}

/* Chat template buttons */
.chat-templates {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.chat-templates::-webkit-scrollbar {
  display: none;
}

.chat-templates button {
  padding: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.chat-templates button:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--accent);
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 6px 16px 12px;
}

.chat-input .btn {
  align-self: flex-end;
  min-height: 38px;
  min-width: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input textarea {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Manager stats */
.manager-stats {
  padding: 24px;
}

.manager-stats h3 {
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 14px;
  text-transform: uppercase;
}

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

.manager-stats-table th,
.manager-stats-table td {
  padding: 8px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.manager-stats-table th {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
}

/* Notification bell */
.notif-bell {
  position: relative;
}

.notif-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.notif-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
  pointer-events: none;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 300;
}

.notif-dropdown-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  font-size: 13px;
}

.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-hover); }


.notif-item.evt-green { background: rgba(34, 197, 94, 0.15); }
.notif-item.evt-yellow { background: rgba(234, 179, 8, 0.15); }
.notif-item.evt-blue { background: rgba(59, 130, 246, 0.15); }
.notif-item.evt-red { background: rgba(239, 68, 68, 0.15); }
.notif-item.evt-orange { background: rgba(249, 115, 22, 0.15); }

.notif-body {
  flex: 1;
  min-width: 0;
}

.notif-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-text {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.notif-time {
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 20px;
}

/* Toast notifications */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  z-index: 1000;
  animation: slideIn 0.3s ease-out;
  max-width: 360px;
}

.toast.toast-success { border-color: var(--green); }
.toast.toast-error { border-color: var(--red); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

/* Deal notes */
.deal-notes {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  resize: none;
  height: 28px;
}

.deal-notes:focus {
  outline: none;
  border-color: var(--accent);
}

/* Manager form */
#manager-form input,
#manager-form select {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}

#manager-form input:focus,
#manager-form select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Responsive */
@media (max-width: 768px) {
  .stats-bar { flex-wrap: wrap; gap: 8px; }
  .stat { min-width: 60px; padding: 6px 12px; }
  .stat-value { font-size: 18px; }
  .filter-group { flex-wrap: wrap; }
  #deals-panel { padding: 0 8px; }
  #deals-table th:nth-child(4),
  #deals-table td:nth-child(4) { display: none; }
}
