/* ═══════════════ NZK DASH Design System ═══════════════ */

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-hover: #1a1a1a;
  --border: #222222;
  --border-focus: #1EDF32;
  --primary: #1EDF32;
  --primary-dim: #19c42b;
  --primary-glow: rgba(30, 223, 50, 0.12);
  --accent: #A654FF;
  --accent-glow: rgba(166, 84, 255, 0.12);
  --secondary: #69DAD4;
  --secondary-glow: rgba(105, 218, 212, 0.12);
  --pink: #ED4AED;
  --pink-glow: rgba(237, 74, 237, 0.12);
  --text: #f5f5f5;
  --text-secondary: #999999;
  --text-muted: #666666;
  --danger: #ff5252;
  --warning: #ffab40;
  --font-display: 'Space Mono', monospace;
  --font-body: 'DM Sans', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--primary); color: var(--bg); }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════ FORM ELEMENTS ═══════════════ */
.nzk-input, .nzk-textarea {
  width: 100%; padding: 12px 16px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 14px; font-family: var(--font-body);
  transition: all 0.2s;
}
.nzk-input:focus, .nzk-textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--primary-glow); }
.nzk-input::placeholder, .nzk-textarea::placeholder { color: var(--text-muted); }
.nzk-textarea { resize: vertical; min-height: 80px; }

.nzk-select {
  width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px; font-family: var(--font-body);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
.nzk-select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--primary-glow); }

/* ═══════════════ BUTTONS ═══════════════ */
.nzk-btn {
  transition: all 0.2s ease; cursor: pointer; border: none; font-family: var(--font-body);
}
.nzk-btn:hover:not(:disabled) { transform: translateY(-1px); }
.nzk-btn:active:not(:disabled) { transform: translateY(0); }
.nzk-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  padding: 12px 24px; border: none; border-radius: 10px;
  color: var(--bg); font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dim));
  letter-spacing: 1.5px; text-transform: uppercase;
}
.btn-primary:disabled { background: var(--text-muted); }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-secondary); font-size: 12px;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn-danger {
  padding: 8px 14px; border: 1px solid rgba(255,82,82,0.3); border-radius: 8px;
  background: rgba(255,82,82,0.08); color: var(--danger); font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-danger:hover { background: rgba(255,82,82,0.15); }

.btn-accent {
  padding: 10px 20px; border: none; border-radius: 8px;
  background: var(--accent); color: var(--bg); font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}

/* ═══════════════ LABELS & ALERTS ═══════════════ */
.label {
  display: block; color: var(--text-secondary); font-size: 12px; font-weight: 600;
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 8px;
}

.error-box {
  background: rgba(255,82,82,0.08); border: 1px solid rgba(255,82,82,0.2);
  border-radius: 10px; padding: 12px 16px; margin-bottom: 16px;
  color: var(--danger); font-size: 13px;
}
.success-box {
  background: var(--primary-glow); border: 1px solid rgba(30, 223, 50, 0.2);
  border-radius: 10px; padding: 12px 16px; margin-bottom: 16px;
  color: var(--primary); font-size: 13px;
}

.spinner {
  width: 18px; height: 18px; border: 2px solid var(--bg); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block;
}
.spinner-dark {
  width: 14px; height: 14px; border: 2px solid var(--text-muted); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle;
}

/* Skeleton loading */
.skeleton { position: relative; overflow: hidden; background: var(--surface); border-radius: 8px; }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.skeleton-row { height: 48px; margin-bottom: 8px; border-radius: 8px; }
.skeleton-card { height: 80px; border-radius: 12px; }
.skeleton-grid { display: flex; gap: 16px; margin-bottom: 24px; }
.skeleton-grid .skeleton { flex: 1; min-width: 150px; }

/* Button loading state */
.nzk-btn.loading { pointer-events: none; opacity: 0.7; }
.nzk-btn.loading .btn-text { visibility: hidden; }
.nzk-btn.loading::after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.nzk-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; }

/* ═══════════════ LAYOUT ═══════════════ */
.screen { display: none; }
.screen.active { display: flex; }

.login-screen {
  height: 100vh; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(30, 223, 50, 0.06) 0%, transparent 60%);
}
.login-card {
  width: 100%; max-width: 400px; padding: 48px 36px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  animation: fadeIn 0.5s ease;
}
.login-card h1 {
  font-family: var(--font-display); font-size: 24px; text-align: center;
  margin-bottom: 8px; color: var(--primary);
}
.login-card p { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn-primary { width: 100%; margin-top: 8px; }

.dashboard {
  height: 100vh; flex-direction: row;
}

/* ═══════════════ TOPBAR ═══════════════ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 52px;
  background: rgba(10,10,10,0.85); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-family: var(--font-display); font-size: 14px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 14px; }

/* Profile flyout */
.profile-menu { position: relative; }
.profile-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.profile-btn:hover { border-color: var(--primary); color: var(--primary); }
.profile-dropdown {
  display: none; position: absolute; right: 0; top: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 200; overflow: hidden;
}
.profile-menu.open .profile-dropdown { display: block; }
.profile-dropdown-name {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.profile-dropdown-name strong { color: var(--text); }
.profile-dropdown button {
  width: 100%; text-align: left; padding: 10px 14px; background: none; border: none;
  color: var(--danger); font-size: 13px; font-family: var(--font-body); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.profile-dropdown button:hover { background: var(--surface-hover); }
.hamburger { display: none; background: none; border: none; color: var(--text); padding: 6px; cursor: pointer; }

.main-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }

/* ═══════════════ SIDEBAR ═══════════════ */
.sidebar {
  width: 220px; min-width: 220px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 20px 12px;
}
.sidebar-logo {
  font-family: var(--font-display); font-size: 18px; color: var(--primary);
  padding: 0 8px 16px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo span { font-size: 12px; color: var(--text-muted); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.sidebar-btn {
  width: 100%; padding: 10px 14px; background: none; border: none; border-radius: 8px;
  color: var(--text-secondary); font-size: 13px; font-family: var(--font-body);
  text-align: left; cursor: pointer; display: flex; align-items: center; gap: 10px;
  transition: all 0.15s;
}
.sidebar-btn:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-btn.active { background: var(--primary-glow); color: var(--primary); font-weight: 600; }

.sidebar-section {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-muted); padding: 16px 14px 6px; font-weight: 600;
}

/* ═══════════════ MAIN CONTENT ═══════════════ */
.main-content {
  flex: 1; overflow-y: auto; padding: 32px 40px;
}

.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }

.tab-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.tab-header h2 {
  font-family: var(--font-display); font-size: 20px; color: var(--text);
  display: flex; align-items: center; gap: 10px;
}

/* ═══════════════ CARDS ═══════════════ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 14px; font-weight: 600; }

/* ═══════════════ TABLE ═══════════════ */
.nzk-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.nzk-table th {
  text-align: left; padding: 10px 12px; color: var(--text-muted);
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  border-bottom: 1px solid var(--border); font-weight: 600;
}
.nzk-table td {
  padding: 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary);
}
.nzk-table tr:hover td { background: var(--surface-hover); }

/* ═══════════════ STATUS BADGES ═══════════════ */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase;
}
.badge-draft { background: rgba(102,102,102,0.15); color: var(--text-muted); }
.badge-sent { background: var(--accent-glow); color: var(--accent); }
.badge-paid { background: var(--primary-glow); color: var(--primary); }
.badge-overdue { background: rgba(255,82,82,0.1); color: var(--danger); }
.badge-partial { background: rgba(237,74,237,0.1); color: #ED4AED; }
.badge-cancelled { background: rgba(102,102,102,0.1); color: var(--text-muted); text-decoration: line-through; }
.badge-accepted { background: var(--primary-glow); color: var(--primary); }
.badge-declined { background: rgba(255,82,82,0.1); color: var(--danger); }
.badge-expired { background: rgba(255,171,64,0.1); color: var(--warning); }

/* ═══════════════ CHAT (Agent) ═══════════════ */
.chat-container {
  display: flex; flex-direction: column; height: calc(100vh - 180px);
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg {
  max-width: 85%; padding: 12px 16px; border-radius: 12px;
  font-size: 14px; line-height: 1.6; animation: fadeIn 0.2s ease;
}
.chat-msg-user {
  align-self: flex-end; background: var(--primary-glow);
  border: 1px solid rgba(0,230,118,0.2); color: var(--text);
}
.chat-msg-ai {
  align-self: flex-start; background: var(--surface);
  border: 1px solid var(--border); color: var(--text-secondary);
}
.chat-msg-ai strong { color: var(--text); }
.chat-msg-system {
  align-self: center; background: rgba(79,195,247,0.08);
  border: 1px solid rgba(79,195,247,0.15); color: var(--accent);
  font-size: 12px; text-align: center; max-width: 100%;
}
.chat-input-row {
  display: flex; gap: 10px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.chat-input-row .nzk-input { flex: 1; }
.chat-send {
  padding: 12px 20px; border: none; border-radius: 10px;
  background: var(--primary); color: var(--bg); font-weight: 700;
  font-size: 13px; cursor: pointer; letter-spacing: 1px; text-transform: uppercase;
}
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Thinking indicator */
.chat-thinking {
  align-self: flex-start; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 13px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  animation: thinkBounce 1.4s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinkBounce {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ═══════════════ TOAST NOTIFICATIONS ═══════════════ */
.toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: 10px; font-size: 13px; font-family: var(--font-body);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease; min-width: 240px; max-width: 380px;
}
.toast.out { animation: toastOut 0.25s ease forwards; }
.toast-success { border-color: rgba(30,223,50,0.3); }
.toast-success .toast-icon { color: var(--primary); }
.toast-error { border-color: rgba(255,82,82,0.3); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info { border-color: rgba(166,84,255,0.3); }
.toast-info .toast-icon { color: var(--accent); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-msg { flex: 1; line-height: 1.4; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* ═══════════════ CONFIRM MODAL ═══════════════ */
.confirm-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 10000; align-items: center; justify-content: center;
}
.confirm-overlay.active { display: flex; }
.confirm-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; width: 90%; max-width: 400px; animation: slideUp 0.2s ease;
  text-align: center;
}
.confirm-box p { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 24px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .nzk-btn { min-width: 100px; justify-content: center; }

/* ═══════════════ FILTER BAR ═══════════════ */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.filter-search { max-width: 280px; }
.filter-select { max-width: 180px; }

/* ═══════════════ OFFLINE BANNER ═══════════════ */
.offline-banner {
  display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 99999;
  padding: 8px; text-align: center; font-size: 12px; font-weight: 600;
  background: var(--danger); color: #fff; letter-spacing: 0.5px;
}
.offline-banner.active { display: block; }

/* ═══════════════ FORM GRID ═══════════════ */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.form-group { display: flex; flex-direction: column; }
.form-group.full { grid-column: 1 / -1; }

/* ═══════════════ MODAL ═══════════════ */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: 90%; max-width: 600px; max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.3s ease;
}
.modal h3 {
  font-family: var(--font-display); font-size: 16px; margin-bottom: 20px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--border);
}

/* ═══════════════ EMPTY STATE ═══════════════ */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ═══════════════ MOBILE ═══════════════ */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  /* Sidebar */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 260px;
    z-index: 100; transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }

  /* Topbar */
  .topbar { padding: 0 12px; height: 48px; }

  /* Main content */
  .main-content { padding: 16px 12px; }

  /* Tab header */
  .tab-header { flex-wrap: wrap; gap: 10px; margin-bottom: 16px; padding-bottom: 12px; }
  .tab-header h2 { font-size: 16px; }
  .tab-header .nzk-btn { font-size: 11px; padding: 8px 14px; }

  /* Forms */
  .form-grid { grid-template-columns: 1fr; }

  /* Modal */
  .modal { width: 96%; max-width: none; padding: 20px 16px; max-height: 90vh; margin: 8px; border-radius: 12px; }
  .modal h3 { font-size: 14px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .nzk-btn { flex: 1; min-width: 100px; text-align: center; justify-content: center; }

  /* Tables → card layout */
  .nzk-table thead { display: none; }
  .nzk-table, .nzk-table tbody, .nzk-table tr, .nzk-table td { display: block; }
  .nzk-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 12px; margin-bottom: 10px; position: relative;
  }
  .nzk-table td {
    padding: 4px 0; border: none; font-size: 13px;
    display: flex; justify-content: space-between; align-items: center;
  }
  .nzk-table td::before {
    content: attr(data-label);
    font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase;
    color: var(--text-muted); font-weight: 600; margin-right: 12px; flex-shrink: 0;
  }
  .nzk-table td:last-child {
    flex-wrap: wrap; gap: 6px; justify-content: flex-start; margin-top: 8px;
    padding-top: 8px; border-top: 1px solid var(--border);
  }
  .nzk-table td:last-child::before { display: none; }

  /* Stat cards */
  .stat-cards, [style*="display:flex"][style*="gap:16px"][style*="margin-bottom:24px"] {
    flex-wrap: wrap !important;
  }
  .stat-cards .card, [style*="flex:1;min-width:150px"] {
    min-width: calc(50% - 8px) !important; flex: unset !important;
  }

  /* Chat */
  .chat-container { height: calc(100vh - 110px); height: calc(100dvh - 110px); }
  .chat-msg { max-width: 92%; font-size: 13px; padding: 10px 12px; }
  .chat-input-row { gap: 6px; padding-top: 10px; }
  .chat-input-row .nzk-input { font-size: 16px; padding: 10px 12px; }
  .chat-send { padding: 10px 14px; font-size: 11px; }

  /* Buttons */
  .btn-ghost { padding: 6px 10px; font-size: 11px; }
  .btn-primary { padding: 10px 18px; font-size: 12px; }

  /* Login */
  .login-card { margin: 16px; padding: 32px 24px; }

  /* Skeleton */
  .skeleton-grid { flex-wrap: wrap; }
  .skeleton-grid .skeleton { min-width: calc(50% - 8px); }

  /* Dashboard grid */
  #dashboardContent [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Filter bar */
  .filter-bar { flex-direction: column; }
  .filter-search, .filter-select { max-width: none; }

  /* Line items in modals */
  [style*="display:flex"][style*="gap:8px"][style*="margin-bottom:8px"] {
    flex-wrap: wrap !important;
  }
  [style*="display:flex"][style*="gap:8px"][style*="margin-bottom:8px"] .nzk-input {
    min-width: 60px;
  }
  [style*="display:flex"][style*="gap:8px"][style*="margin-bottom:8px"] .nzk-input[style*="flex:3"] {
    flex: 1 1 100% !important;
  }
}
