/**
 * NEXUSNEST MAIN APPLICATION STYLESHEET
 * Premium Dark Studio Aesthetic with Vibrant Accents & Responsive Layout
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@500;600;700;800;900&display=swap');

:root {
  --bg-primary: #080b11;
  --bg-secondary: #0f1420;
  --bg-surface: #151b2b;
  --bg-surface-elevated: #1c2438;
  
  --border-subtle: #1e293b;
  --border-medium: #334155;
  --border-accent: #74a42b;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #74a42b;
  --accent-primary-hover: #5d8422;
  --accent-secondary: #22c55e;
  --accent-indigo: #6366f1;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   AUTHENTICATION OVERLAY (GLASSMORPHIC LOGIN)
   ========================================================================== */
.auth-login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 13, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  padding: 20px;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(116, 164, 43, 0.2);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: authFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authFadeIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.auth-logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--accent-primary);
  object-fit: cover;
  background: #ffffff;
  margin-bottom: 4px;
}

.auth-brand h2 {
  font-size: 1.35rem;
  font-weight: 800;
  font-family: var(--font-display);
  color: #ffffff;
  letter-spacing: -0.02em;
}

.auth-brand p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.auth-error-box {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fda4af;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  text-align: center;
}

.auth-footer-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  padding-top: 14px;
}

/* ==========================================================================
   APP LAYOUT & SIDEBAR
   ========================================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
  transition: filter 0.2s ease;
}

.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-logo-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--accent-primary);
  background: #ffffff;
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  font-family: var(--font-display);
}

.brand-info span {
  font-size: 0.72rem;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-link.active {
  background: rgba(116, 164, 43, 0.15);
  color: #bbf7d0;
  border-color: rgba(116, 164, 43, 0.4);
}

.nav-link svg {
  width: 18px;
  height: 18px;
}

/* User Profile & Sidebar Footer */
.sidebar-user-section {
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.user-profile-compact {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.user-details-compact {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.current-user-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-role-badge {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  width: fit-content;
}

.badge-admin { background: rgba(234, 88, 12, 0.2); color: #fb923c; border: 1px solid rgba(234, 88, 12, 0.4); }
.badge-staff { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.btn-logout:hover {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.15);
}

.sidebar-footer {
  padding: 8px 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
}

/* ==========================================================================
   MAIN WRAPPER & TOP BAR
   ========================================================================== */
.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top-bar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
  flex-wrap: wrap;
  gap: 12px;
}

.top-bar-title h2 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: var(--font-display);
}

.top-bar-title p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switch-group {
  display: flex;
  background: var(--bg-surface);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-medium);
}

.mode-btn {
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.mode-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(116, 164, 43, 0.4);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 1;
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-medium);
}
.btn-secondary:hover {
  background: var(--bg-surface-elevated);
}

.btn-accent {
  background: linear-gradient(135deg, #74a42b 0%, #4d7c0f 100%);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(116, 164, 43, 0.4);
}
.btn-accent:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-outline-danger {
  background: transparent;
  color: var(--accent-rose);
  border-color: rgba(244, 63, 94, 0.3);
}
.btn-outline-danger:hover {
  background: rgba(244, 63, 94, 0.15);
}

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

/* Tabs */
.tab-content {
  display: none;
  padding: 24px 28px;
}
.tab-content.active {
  display: block;
}

/* ==========================================================================
   STUDIO DUAL PANE & RESPONSIVE PREVIEW
   ========================================================================== */
.studio-grid {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1200px) {
  .studio-grid {
    grid-template-columns: 400px 1fr;
    gap: 16px;
  }
}

@media (max-width: 1000px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

/* Editor Panel */
.editor-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.section-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-title svg {
  width: 15px;
  height: 15px;
  color: var(--accent-primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-control, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(116, 164, 43, 0.25);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

textarea.form-control {
  min-height: 90px;
  resize: vertical;
  line-height: 1.4;
}

.client-select-wrapper {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   2-TIER SPACIOUS LINE ITEM CARD BUILDER (NO SQUISHING)
   ========================================================================== */
.items-builder-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease;
}

.item-row-card:hover {
  border-color: var(--border-medium);
}

.item-card-top {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.item-field-date {
  width: 130px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-field-date label,
.item-field-desc label,
.item-field-price label,
.item-field-qty label,
.item-field-total label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.item-field-desc {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.item-desc-input {
  width: 100%;
  font-size: 0.88rem;
}

.item-card-bottom {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 10px;
  align-items: flex-end;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 8px;
}

.item-field-price,
.item-field-qty,
.item-field-total {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.qty-na-wrapper {
  display: flex;
  gap: 6px;
  align-items: center;
}

.qty-na-wrapper input[type="number"] {
  width: 60px;
}

.na-checkbox-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.line-total-display {
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  text-align: right;
  color: #86efac;
}

.item-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  height: 36px;
}

.item-delete-btn:hover {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.15);
}

/* ==========================================================================
   PREVIEW PANE WITH RESPONSIVE ZOOM CONTROLLER
   ========================================================================== */
.preview-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 80px;
}

.preview-toolbar {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.preview-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.zoom-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.preview-viewport-outer {
  width: 100%;
  overflow: auto;
  background: #04070d;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 20px;
  display: flex;
  justify-content: center;
  min-height: 600px;
  max-height: calc(100vh - 160px);
}

.preview-viewport-inner {
  transform-origin: top center;
  transition: transform 0.15s ease-out;
  display: flex;
  justify-content: center;
}

/* ==========================================================================
   DASHBOARD STATS & DATA TABLES
   ========================================================================== */
.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1300px;
  margin: 0 auto;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-display);
}

.text-success { color: #86efac !important; }
.text-danger { color: #fda4af !important; }

.table-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header-bar {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background: var(--bg-surface);
  padding: 12px 18px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}

/* Status Pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-paid { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.3); }
.status-pending { background: rgba(245, 158, 11, 0.15); color: #fde047; border: 1px solid rgba(245, 158, 11, 0.3); }
.status-overdue { background: rgba(244, 63, 94, 0.15); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.3); }
.status-draft { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }

/* ==========================================================================
   MODALS & OVERLAYS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-display);
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Quick Preview Modal */
.modal-preview-card {
  max-width: 860px;
  width: 95%;
  background: #0f1420;
}

.modal-preview-body {
  padding: 16px;
  display: flex;
  justify-content: center;
  max-height: 80vh;
  overflow-y: auto;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 99999;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  min-width: 260px;
  animation: toastSlide 0.25s ease-out;
  transition: all 0.3s ease;
}
.toast-success { border-left: 4px solid var(--accent-primary); }
.toast-info { border-left: 4px solid var(--accent-indigo); }
.toast-error { border-left: 4px solid var(--accent-rose); }

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

.code-box {
  background: #070a0f;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #86efac;
  max-height: 380px;
  overflow: auto;
  white-space: pre-wrap;
}
