@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ─── Design Tokens (Dark Theme — default) ───────────────────────── */
:root {
  --bg: #0d0f1a;
  --bg-card: #13162a;
  --bg-2: #13162a;
  --bg-3: #1a1e36;
  --bg-hover: #1a1e36;
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(99, 102, 241, 0.4);

  --text-1: #e8eaf6;
  --text: #e8eaf6;
  --text-2: #8f95b2;
  --text-3: #5a6080;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.15);
  --accent-glow: 0 0 20px rgba(99, 102, 241, 0.3);

  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);

  --sidebar-w: 240px;
  --header-h: 60px;
  --transition: 0.18s ease;
}

/* ─── Light Theme ────────────────────────────────────────────────── */
:root[data-theme="light"] {
  --bg: #f0f2f8;
  --bg-card: #ffffff;
  --bg-2: #ffffff;
  --bg-3: #f4f5fb;
  --bg-hover: #eef0fb;
  --border: rgba(0, 0, 0, 0.08);
  --border-accent: rgba(99, 102, 241, 0.35);

  --text-1: #1a1c2e;
  --text: #1a1c2e;
  --text-2: #5a5f80;
  --text-3: #9095b8;

  --accent: #5254cc;
  --accent-hover: #4142a8;
  --accent-light: rgba(99, 102, 241, 0.10);
  --accent-glow: 0 0 20px rgba(99, 102, 241, 0.15);

  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.10);
  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.10);
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.10);

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Smooth theme transition */
*,
*::before,
*::after {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.15s ease;
}

/* ─── Reset & Base ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
}

input,
textarea,
select {
  font-family: inherit;
}

/* ─── Login Page ─────────────────────────────────────────────────── */
#login-page {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, 0.12) 0%, transparent 60%),
    var(--bg);
}

#login-page.active {
  display: flex;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow), var(--accent-glow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  box-shadow: var(--accent-glow);
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  color: var(--text-2);
  font-size: 13px;
  margin-top: 4px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-field textarea {
  resize: vertical;
  min-height: 100px;
}

.form-field select option {
  background: #1a1e36;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #6366f1);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.25);
}

.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(34, 197, 94, 0.35);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

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

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.error-msg {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ─── App Shell ──────────────────────────────────────────────────── */
#app {
  display: none;
  height: 100vh;
  overflow: hidden;
}

#app.active {
  display: flex;
}

/* ─── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-title {
  font-weight: 700;
  font-size: 15px;
}

.sidebar-sub {
  font-size: 10px;
  color: var(--text-3);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13.5px;
  font-weight: 400;
  user-select: none;
  margin-bottom: 1px;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.nav-item .icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-3);
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-3);
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}

.logout-btn:hover {
  color: var(--red);
}

/* ─── Content Area ───────────────────────────────────────────────── */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.content-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card+.card {
  margin-top: 16px;
}

/* ─── Stats Row ──────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

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

/* ─── Filters Bar ────────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus {
  border-color: var(--accent);
}

.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.filter-select:focus {
  border-color: var(--accent);
}

.filter-select option {
  background: #1a1e36;
}

/* ─── Table ──────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background var(--transition);
}

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

tbody tr {
  cursor: pointer;
}

.invoice-num {
  font-weight: 600;
  color: var(--accent);
  font-size: 13px;
}

.project-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-created {
  background: var(--amber-bg);
  color: var(--amber);
}

.status-paid {
  background: var(--green-bg);
  color: var(--green);
}

.status-partial {
  background: var(--accent-light);
  color: var(--accent);
}

.status-abandoned {
  background: var(--red-bg);
  color: var(--red);
}

.status-test {
  background: #ecfeff;
  color: #0f766e;
}

.amount-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.text-muted {
  color: var(--text-2);
}

.text-xs {
  font-size: 12px;
}

/* ─── Pagination ─────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}

.pagination-controls {
  display: flex;
  gap: 6px;
}

.page-btn {
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-2);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.page-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ─── Invoice Detail ─────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.detail-section {
  margin-bottom: 20px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.detail-label {
  font-size: 12px;
  color: var(--text-3);
  flex-shrink: 0;
  width: 140px;
  margin-top: 1px;
}

.detail-value {
  font-size: 13px;
  color: var(--text);
  flex: 1;
}

.detail-value.big {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.invoice-file-preview {
  margin-top: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  text-align: center;
}

.invoice-file-preview img {
  max-width: 100%;
  max-height: 500px;
  display: block;
  margin: 0 auto;
}

/* ─── Audit Log ──────────────────────────────────────────────────── */
.audit-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audit-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.audit-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
  flex-shrink: 0;
}

.audit-dot.created {
  background: var(--text-3);
}

.audit-dot.marked_paid {
  background: var(--green);
}

.audit-dot.email {
  background: var(--amber);
}

.audit-dot.callback {
  background: #60a5fa;
}

.audit-dot.marked_partially_paid {
  background: var(--accent);
}

.audit-content {
  flex: 1;
}

.audit-action {
  font-size: 13px;
  font-weight: 500;
}

.audit-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

.audit-details {
  font-size: 11px;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  margin-top: 6px;
  font-family: monospace;
  word-break: break-all;
}

/* ─── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}

.modal-close:hover {
  color: var(--text);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ─── Empty State ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}

.empty-state .icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
}

/* ─── Misc Utilities ─────────────────────────────────────────────── */
.flex {
  display: flex;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.mt-2 {
  margin-top: 8px;
}

.mt-4 {
  margin-top: 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 9999;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  border-left: 3px solid var(--green);
}

.toast.error {
  border-left: 3px solid var(--red);
}

/* ─── Responsive: hide sidebar on tiny screens ───────────────────── */
@media (max-width: 640px) {
  #app.active {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .sidebar-header {
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .sidebar-nav {
    display: flex;
    padding: 8px;
    overflow-x: auto;
    flex-direction: row;
  }

  .sidebar-user {
    display: none;
  }

  .nav-section-title {
    display: none;
  }
}

/* scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}
