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

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

:root {
  --bg: #f4f5f7;
  --white: #ffffff;
  --border: #e0e0e0;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --text: #1a1a2e;
  --text-sec: #6b7280;
  --green-bg: #dcfce7;
  --green-text: #16a34a;
  --red-bg: #fee2e2;
  --red-text: #dc2626;
  --orange-bg: #fff7ed;
  --orange-text: #ea580c;
  --sidebar-w: 220px;
}

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

/* ── LAYOUT ── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}
.sidebar-logo p {
  font-size: 11px;
  color: var(--text-sec);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-sec);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover { background: #f0f4ff; color: var(--accent); }
.sidebar-nav a.active { background: #eff6ff; color: var(--accent); }
.sidebar-nav a svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-bottom {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}
.sidebar-bottom a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-sec);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.sidebar-bottom a:hover { background: var(--red-bg); color: var(--red-text); }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

/* ── CARDS ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── STAT CARDS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-sec);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-card .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-top: 6px;
  line-height: 1.3;
}
.stat-card .sub {
  font-size: 12px;
  color: var(--text-sec);
  margin-top: 4px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--white); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: var(--red-bg); color: var(--red-text); }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: var(--green-bg); color: var(--green-text); }
.btn-success:hover { background: #bbf7d0; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn svg { width: 15px; height: 15px; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: #f9fafb;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid #f0f0f0; transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
tbody tr:nth-child(even) { background: #f9fafb; }
tbody tr:nth-child(even):hover { background: #f0f4ff; }
td { padding: 10px 14px; font-size: 13.5px; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-orange { background: var(--orange-bg); color: var(--orange-text); }
.badge-gray { background: #f3f4f6; color: var(--text-sec); }
.badge-overdue { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-sec);
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  font-size: 18px;
}
.modal-close:hover { background: #f3f4f6; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { font-size: 13px; color: var(--text-sec); margin-top: 2px; }

/* ── TOAST ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.2s ease;
  min-width: 260px;
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── FILTER TABS ── */
.filter-tabs {
  display: flex;
  gap: 4px;
  background: #f3f4f6;
  padding: 4px;
  border-radius: var(--radius);
  width: fit-content;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-sec);
  transition: all 0.15s;
}
.filter-tab.active { background: var(--white); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* ── LOGIN PAGE ── */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  padding: 40px 36px;
  width: 360px;
}
.login-box .logo { text-align: center; margin-bottom: 28px; }
.login-box .logo h1 { font-size: 26px; font-weight: 700; color: var(--accent); }
.login-box .logo p { font-size: 13px; color: var(--text-sec); margin-top: 4px; }

/* ── CHART ── */
.chart-wrap { height: 200px; position: relative; }

/* ── ACTIONS ── */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── INVOICE LAYOUT ── */
.nova-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

/* ── STAVKE TABLE ── */
.stavke-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stavke-table th {
  background: #f9fafb;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-sec);
  text-align: left;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}
.stavke-table td { padding: 6px 6px; border-bottom: 1px solid #f0f0f0; }
.stavke-table input, .stavke-table select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.stavke-table input:focus, .stavke-table select:focus {
  border-color: var(--accent);
}
.stavke-table .del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-sec);
  padding: 4px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
}
.stavke-table .del-btn:hover { background: var(--red-bg); color: var(--red-text); }
.total-row { text-align: right; margin-top: 12px; font-size: 15px; }
.total-row strong { font-size: 18px; color: var(--accent); }

/* ── A4 INVOICE PREVIEW ── */
.invoice-bg {
  background: #e5e7eb;
  min-height: 100vh;
  padding: 32px 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.invoice-actions-bar {
  position: fixed;
  top: 20px;
  right: 24px;
  display: flex;
  gap: 8px;
  z-index: 50;
}
.a4 {
  background: #fff;
  width: 794px;
  min-height: 1123px;
  padding: 60px 56px 40px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #1a1a2e;
}
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; }
.inv-company h2 { font-size: 22px; font-weight: 700; color: var(--accent); }
.inv-company p { font-size: 12px; color: #555; line-height: 1.7; margin-top: 4px; }
.inv-title { text-align: right; }
.inv-title h1 { font-size: 28px; font-weight: 700; letter-spacing: 2px; color: #1a1a2e; }
.inv-title .inv-number { font-size: 14px; color: var(--text-sec); margin-top: 4px; }
.inv-title .inv-date { font-size: 12px; color: var(--text-sec); margin-top: 2px; }

.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-bottom: 36px; }
.inv-party h4 { font-size: 11px; font-weight: 600; color: var(--text-sec); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 8px; }
.inv-party p { font-size: 12.5px; line-height: 1.8; color: #333; }
.inv-party strong { color: #1a1a2e; }

.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.inv-table th {
  background: #f3f4f6;
  padding: 9px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-sec);
  text-align: left;
  border-bottom: 2px solid var(--border);
  text-transform: uppercase;
}
.inv-table td { padding: 9px 12px; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.inv-table tr:last-child td { border-bottom: none; }
.inv-table .text-right { text-align: right; }

.inv-totals { display: flex; justify-content: flex-end; margin-bottom: 36px; }
.inv-totals-box { width: 280px; }
.inv-totals-box .total-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
}
.inv-totals-box .total-grand {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.inv-payment { margin-bottom: 24px; }
.inv-payment h4 { font-size: 11px; font-weight: 600; color: var(--text-sec); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 8px; }
.inv-payment p { font-size: 12.5px; line-height: 1.8; color: #333; }

.inv-footer { border-top: 1px solid var(--border); padding-top: 16px; }
.inv-footer p { font-size: 11px; color: var(--text-sec); line-height: 1.7; }

@media print {
  @page { size: A4; margin: 0; }

  body { background: white; }

  .invoice-actions-bar,
  #toast-container,
  .sidebar,
  nav { display: none !important; }

  .invoice-bg { background: white; padding: 0; margin: 0; }

  .a4 {
    box-shadow: none;
    margin: 0;
    padding: 40px 45px;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .inv-footer { margin-top: auto; }
}
