/* ============================================
   KirimWA-Go Dashboard — Design System
   Dark Theme | Sprint 2
   ============================================ */

/* --- Variables --- */
:root {
  --bg-primary:   #0d0d14;
  --bg-surface:   #1a1a28;
  --bg-elevated:  #22223a;
  --bg-hover:     #2a2a42;
  --accent:       #25d366;
  --accent-dim:   #1aab52;
  --accent-glow:  rgba(37, 211, 102, 0.15);
  --text-primary: #e8eaf6;
  --text-secondary: #8892a4;
  --text-muted:   #4a5568;
  --border:       #2a2a3e;
  --border-focus: #25d366;
  --error:        #f56565;
  --error-bg:     rgba(245, 101, 101, 0.1);
  --warning:      #f6ad55;
  --success:      #25d366;
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --radius-full:  9999px;
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.5);
  --shadow-glow:  0 0 20px rgba(37, 211, 102, 0.2);
  --sidebar-w:    220px;
  --header-h:     56px;
  --transition:   0.18s ease;
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Login Page --- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(37,211,102,0.08) 0%, transparent 70%);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px 32px;
  width: 340px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-logo {
  width: 48px;
  height: 48px;
  background: var(--accent-glow);
  border: 1px solid rgba(37,211,102,0.3);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.login-brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.login-brand p {
  font-size: 12px;
  color: var(--text-secondary);
}

/* PIN Display */
.pin-display {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  height: 48px;
}

.pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background var(--transition), border-color var(--transition), transform 0.15s ease;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.15);
}

/* Error message */
.error-msg {
  font-size: 12px;
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid rgba(245,101,101,0.2);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  width: 100%;
  text-align: center;
  display: none;
}

.error-msg.visible {
  display: block;
}

/* PIN Pad */
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.pin-btn {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 0.1s ease, box-shadow var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pin-btn:hover {
  background: var(--bg-hover);
  border-color: rgba(37,211,102,0.3);
}

.pin-btn:active {
  transform: scale(0.92);
  background: var(--accent-glow);
  border-color: var(--accent);
}

.pin-btn.digit {
  font-size: 20px;
}

.pin-btn.clear {
  font-size: 16px;
  color: var(--text-secondary);
}

.pin-btn.submit {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-size: 20px;
}

.pin-btn.submit:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  box-shadow: var(--shadow-glow);
}

.pin-btn.submit:active {
  transform: scale(0.92);
}

/* Shake animation for wrong PIN */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-8px); }
  30%       { transform: translateX(8px); }
  45%       { transform: translateX(-6px); }
  60%       { transform: translateX(6px); }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(3px); }
}

.pin-display.shake {
  animation: shake 0.45s ease;
}

/* --- App Layout --- */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.sidebar-logo {
  width: 30px;
  height: 30px;
  background: var(--accent-glow);
  border: 1px solid rgba(37,211,102,0.3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(37,211,102,0.15);
}

.nav-item .nav-icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.sidebar-footer .version {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 10px;
  margin-bottom: 4px;
}

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.topbar {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.status-badge.online {
  background: rgba(37,211,102,0.12);
  color: var(--accent);
  border: 1px solid rgba(37,211,102,0.2);
}

.status-badge.offline {
  background: rgba(245,101,101,0.1);
  color: var(--error);
  border: 1px solid rgba(245,101,101,0.2);
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Page sections */
.page-section {
  display: none;
}

.page-section.active {
  display: block;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.page-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.empty-state .empty-icon {
  font-size: 40px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 13px;
  max-width: 240px;
  line-height: 1.6;
}

/* Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

/* Stat grid for dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-value.accent { color: var(--accent); }

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), box-shadow var(--transition), transform 0.1s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-dim);
  box-shadow: var(--shadow-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* --- Page header row (title + action button) --- */
.page-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

/* --- Button sizes --- */
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  gap: 4px;
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: rgba(245,101,101,0.3);
}

.btn-danger:hover {
  background: var(--error-bg);
  border-color: var(--error);
}

/* --- Status badge variants (for instance cards) --- */
.status-badge.connected {
  background: rgba(37,211,102,0.12);
  color: var(--accent);
  border: 1px solid rgba(37,211,102,0.2);
}

.status-badge.connecting {
  background: rgba(246,173,85,0.1);
  color: var(--warning);
  border: 1px solid rgba(246,173,85,0.25);
}

.status-badge.disconnected {
  background: rgba(74,85,104,0.15);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* --- Instance list --- */
.instance-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.instance-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}

.instance-card:hover {
  border-color: rgba(37,211,102,0.2);
}

.instance-card-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.instance-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.instance-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.instance-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* --- Loader spinner --- */
.instances-loader {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 400px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-md);
  transform: scale(0.96) translateY(8px);
  transition: transform 0.18s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* --- Form elements --- */
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

.form-hint code {
  background: var(--bg-elevated);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: monospace;
}

/* --- Toast notification --- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  padding: 10px 16px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-width: 320px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.toast.toast-success {
  border-color: rgba(37,211,102,0.3);
  color: var(--accent);
}

.toast.toast-error {
  border-color: rgba(245,101,101,0.3);
  color: var(--error);
}

/* --- QR Modal --- */
.modal-qr {
  width: 460px;
}

.qr-modal-body {
  align-items: center;
  min-height: 300px;
  justify-content: center;
}

.qr-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

.qr-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.qr-image {
  width: 224px;
  height: 224px;
  border-radius: var(--radius-md);
  border: 3px solid var(--border);
  background: #fff;
  display: block;
  image-rendering: pixelated;
}

.qr-helper {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.7;
}

.qr-helper strong {
  color: var(--text-primary);
}

.qr-countdown {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.qr-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 0;
}

.qr-success-icon {
  font-size: 52px;
  line-height: 1;
}

.qr-success p {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

/* --- Settings Page --- */
.settings-section {
  margin-bottom: 24px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
  padding: 0 2px;
}

.settings-card {
  padding: 0;
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  flex-shrink: 0;
}

.settings-row-value {
  font-size: 13px;
  color: var(--text-primary);
  text-align: right;
}

.settings-row-value code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  background: var(--bg-elevated);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--accent);
}

.settings-apikey-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.apikey-display {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 3px;
}

.apikey-display.revealed {
  color: var(--text-primary);
  letter-spacing: normal;
  font-size: 11px;
  word-break: break-all;
}

.apikey-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
}

.settings-form .btn-primary {
  align-self: flex-start;
  margin-top: 4px;
}

.pin-change-msg {
  font-size: 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  display: none;
}

.pin-change-msg.visible {
  display: block;
}

.pin-change-msg.success {
  background: rgba(37,211,102,0.1);
  color: var(--accent);
  border: 1px solid rgba(37,211,102,0.2);
}

.pin-change-msg.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(245,101,101,0.2);
}

/* --- Test Send Modal --- */
.form-textarea {
  resize: vertical;
  min-height: 90px;
}

.send-result {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  line-height: 1.6;
  word-break: break-all;
}

.send-result.success {
  background: rgba(37,211,102,0.08);
  color: var(--accent);
  border: 1px solid rgba(37,211,102,0.2);
}

.send-result.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(245,101,101,0.2);
}

/* --- Disabled button --- */
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
