@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #181818;
  --surface: #1e1e1e;
  --surface2: #2a2a2a;
  --text: #e5e5e5;
  --muted: #a0a0a0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #333;
}

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

body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

nav {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

nav a, nav button {
  font-family: 'Poppins', sans-serif;
  color: var(--text);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

nav a:hover, nav button:hover { background: var(--surface2); }
nav a.active { background: var(--accent); color: #fff; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

h1, h2, h3 { margin-bottom: 1rem; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

input, select, textarea {
  font-family: 'Poppins', sans-serif;
  width: 100%;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

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

textarea { min-height: 80px; resize: vertical; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(255,255,255,0.03); }

.btn {
  font-family: 'Poppins', sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
}

.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--border); }
.btn.success { background: var(--success); }
.btn.warning { background: var(--warning); color: #000; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 0.35rem 0.6rem; font-size: 0.78rem; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  line-height: 1.4;
}

.badge.pending { background: #3f3f00; color: #f59e0b; }
.badge.unpaid { background: #3f1f00; color: #f97316; }
.badge.paid { background: #0f3f1f; color: #22c55e; }
#detailPanel .field span.badge-wrap { max-width: none; word-break: normal; }
.num { text-align: right !important; padding-right: 1.5rem !important; min-width: 100px; }
table td:last-child, table th:last-child { text-align: right !important; }
table td.actions { justify-content: flex-end !important; }
.badge.cancelled { background: #3f0000; color: #ef4444; }
.badge.partially-paid { background: #3f2f00; color: #f59e0b; }
.badge.quote { background: #1f2f4f; color: #60a5fa; }
.badge.invoice { background: #1f1f4f; color: #a78bfa; }
.badge.beta { background: #3f0f2f; color: #f472b6; }
.badge.planning { background: rgba(148,163,184,0.15); color: #94a3b8; }
.badge.active { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge.completed { background: rgba(59,130,246,0.15); color: #3b82f6; }
.badge.internal { background: rgba(168,85,247,0.15); color: #a855f7; }
.badge.external { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge.others { background: rgba(107,114,128,0.15); color: #6b7280; }

.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

.item-row {
  display: grid;
  grid-template-columns: 1fr 100px 140px 140px 40px;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  padding: 1.5rem;
}

.modal h3 { margin-bottom: 1rem; }
.modal .actions { margin-top: 1rem; justify-content: flex-end; }

/* Invoice preview — matches sample exactly */
.invoice-preview {
  background: #fff;
  color: #111;
  padding: 2rem 2.5rem;
  border-radius: 0.75rem;
  max-width: 800px;
  margin: 0 auto;
  font-family: 'Poppins', sans-serif;
}

.invoice-preview .preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.invoice-preview .preview-header .logo-area {
  width: 33.333%;
}

.invoice-preview .preview-header .logo-area img {
  max-width: 100%;
  height: auto;
}

.invoice-preview .preview-header .type-area {
  width: 33.333%;
  text-align: right;
  font-size: 1.75rem;
  font-weight: 800;
  color: #111;
}

.invoice-preview .preview-header .meta-area {
  width: 33.333%;
  text-align: right;
  color: #111;
  font-size: 0.9rem;
}

.invoice-preview .preview-header .meta-area > div {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
  margin-bottom: 0.15rem;
}

.invoice-preview .preview-header .meta-area .meta-label {
  font-weight: 700;
}

.invoice-preview .info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  color: #111;
  font-size: 0.9rem;
}

.invoice-preview .info-row .from {
  width: 50%;
  line-height: 1.6;
}

.invoice-preview .info-row .to {
  width: 50%;
  text-align: right;
}

.invoice-preview .info-row .to .to-label {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.invoice-preview table {
  width: 100%;
  border-collapse: collapse;
  color: #111;
  font-size: 0.9rem;
}

.invoice-preview thead th {
  text-align: left;
  padding: 0.5rem 0;
  border-bottom: 2px solid #d1d5db;
  font-weight: 700;
  color: #111;
}

.invoice-preview thead th:last-child,
.invoice-preview tbody td:last-child {
  text-align: right;
}

.invoice-preview tbody td {
  padding: 0.35rem 0;
  border-bottom: 1px solid #e5e7eb;
  color: #111;
}

.invoice-preview .subtotal-row td {
  border-bottom: none;
  padding-top: 1.25rem;
  font-weight: 700;
}

.invoice-preview .subtotal-row td:last-child {
  text-align: right;
}

.invoice-preview .fees-header th {
  border-bottom: 2px solid #d1d5db;
  padding-top: 0.5rem;
  font-weight: 700;
}

.invoice-preview .fees-header th:last-child {
  text-align: right;
}

.invoice-preview .total-section td {
  border-bottom: none;
  padding-top: 0.75rem;
  font-weight: 700;
}

.invoice-preview .total-section td:last-child {
  text-align: right;
}

.invoice-preview .grand-total td {
  font-size: 1.5rem;
  font-weight: 800;
  padding-top: 1rem;
}

.invoice-preview .currency-row td:last-child {
  text-align: right;
  font-weight: 700;
  font-size: 1rem;
}

.invoice-preview .tagline {
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  padding-top: 1.5rem;
  color: #111;
}

.invoice-preview .terms-area {
  margin-top: 1.5rem;
  color: #111;
  font-size: 0.85rem;
}

.invoice-preview .terms-area .terms-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 2rem;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-box h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #fff;
}
.modal-box p {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 1.5rem;
}
.modal-box .actions {
  justify-content: flex-end;
  gap: 0.75rem;
}
.modal-box .actions .btn {
  font-size: 0.95rem;
  padding: 0.65rem 1.25rem;
}
.modal-box input[type="text"],
.modal-box input[type="number"] {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  margin-bottom: 1.5rem;
}

.sidebar {
  position: fixed; top: 0; left: 0; width: 240px; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  z-index: 100; display: flex; flex-direction: column;
}
.sidebar-toggle {
  padding: 1rem; cursor: pointer; font-size: 1.25rem; text-align: right; border-bottom: 1px solid var(--border);
}
.sidebar-content { flex: 1; overflow-y: auto; }
.sidebar-group-header {
  padding: 0.65rem 1rem; font-size: 0.78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border);
}
.sidebar-group-header:hover { background: var(--surface2); }
.sidebar-group-links { display: flex; flex-direction: column; }
.sidebar-group-links a {
  padding: 0.55rem 1rem 0.55rem 1.5rem; color: var(--text); text-decoration: none; font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-group-links a:hover, .sidebar-group-links a.active { background: var(--accent); color: #fff; }
.sidebar-link {
  display: block; padding: 0.65rem 1rem; color: var(--text); text-decoration: none; font-size: 0.9rem;
  font-weight: 500; border-bottom: 1px solid var(--border);
}
.sidebar-link:hover, .sidebar-link.active { background: var(--accent); color: #fff; }
body.has-sidebar .container { margin-left: 240px; max-width: none; }
body.has-sidebar.sidebar-collapsed .container { margin-left: 48px; }
.sidebar-collapsed .sidebar { width: 48px; overflow: hidden; }
.sidebar-collapsed .sidebar-content { display: none; }
.sidebar-collapsed .sidebar-toggle { text-align: center; padding: 1rem 0; }

@media print {
  nav, .sidebar, .no-print { display: none !important; }
  .invoice-preview {
    box-shadow: none;
    border: none;
    border-radius: 0;
    max-width: 100%;
  }
  body { background: #fff; color: #111; }
}

@media (max-width: 700px) {
  .item-row { grid-template-columns: 1fr 80px 100px 100px 40px; }
  .invoice-preview { padding: 1.25rem; }
  .invoice-preview .preview-header { flex-wrap: wrap; }
  .invoice-preview .preview-header .logo-area,
  .invoice-preview .preview-header .type-area,
  .invoice-preview .preview-header .meta-area { width: 100%; text-align: left; }
  .invoice-preview .preview-header .meta-area > div { justify-content: flex-start; }
  .invoice-preview .info-row .to { text-align: left; margin-top: 1rem; }
  .invoice-preview .info-row { flex-wrap: wrap; }
}
