:root {
  --bg: #0b1020;
  --card: #1a2332;
  --card-light: #222d42;
  --text: #e9eeff;
  --muted: #a8b1d6;
  --line: rgba(255, 255, 255, 0.08);
  --btn: #2a3754;
  --btn-hover: #364a6f;
  --primary: #4a90e2;
  --primary-hover: #5ba3ff;
  --danger: #ff6b6b;
  --danger-hover: #ff5252;
  --success: #4caf50;
  --warning: #ff9800;
  --shadow: rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #0b1020 0%, #1a2332 100%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px var(--shadow);
}

.brand h1 {
  margin: 0 0 4px 0;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #4a90e2, #5ba3ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand p {
  margin: 0;
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
  border: 1px solid var(--line);
  background: var(--btn);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--btn-hover);
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
}

.btn.file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn.file input {
  display: none;
}

.btn-icon {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
}

.btn-icon:hover {
  color: var(--text);
}

/* ===== TABS ===== */
.tabs {
  position: sticky;
  top: 73px;
  z-index: 99;
  display: flex;
  gap: 4px;
  padding: 8px 24px;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--line);
  overflow-x: auto;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 12px 20px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
  white-space: nowrap;
  position: relative;
}

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

.tab.active {
  background: var(--card);
  color: var(--primary);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

/* ===== CONTAINER ===== */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s;
}

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

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.card-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

/* ===== FORMS ===== */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card-light);
  color: var(--text);
  outline: none;
  font-size: 14px;
  transition: all 0.2s;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  background: rgba(74, 144, 226, 0.05);
}

.field input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.field input::placeholder {
  color: rgba(168, 177, 214, 0.4);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.params-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
  align-items: end;
  margin-bottom: 24px;
}

.btnField button {
  width: 100%;
}

.invoice-form {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr 1.5fr;
  gap: 12px;
  margin-bottom: 16px;
}

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

/* ===== TABLES ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

.table.compact {
  min-width: 1200px;
}

.table th,
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  background: rgba(255, 255, 255, 0.02);
}

.table tbody tr {
  transition: background 0.2s;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

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

.table td input,
.table td select {
  padding: 6px 8px;
  font-size: 13px;
}

.iconbtn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.iconbtn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.iconbtn.danger {
  border-color: rgba(255, 107, 107, 0.3);
  color: var(--danger);
}

.iconbtn.danger:hover {
  background: rgba(255, 107, 107, 0.15);
}

.cellNum input {
  width: 100px;
}

.cellTxt input {
  width: 150px;
}

.cellTotal {
  font-weight: 800;
  white-space: nowrap;
}

/* ===== CHART ===== */
.chart-wrap {
  height: 450px;
  padding: 16px 0;
  margin-bottom: 24px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ===== SORTABLE COLUMNS ===== */
.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.sortable:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}

.sort-icon {
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.sortable:hover .sort-icon {
  opacity: 1;
}

.sortable.asc .sort-icon::after {
  content: ' ▲';
}

.sortable.desc .sort-icon::after {
  content: ' ▼';
}

/* ===== PILL ===== */
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  border-color: rgba(76, 175, 80, 0.4);
  color: var(--success);
  background: rgba(76, 175, 80, 0.1);
}

.pill.warn {
  border-color: rgba(255, 152, 0, 0.4);
  color: var(--warning);
  background: rgba(255, 152, 0, 0.1);
}

.pill.bad {
  border-color: rgba(255, 107, 107, 0.4);
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
}

/* ===== BUDGET GRID ===== */
.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.budget-card {
  background: var(--card-light);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  transition: all 0.2s;
}

.budget-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow);
}

.budget-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.budget-card-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.budget-stats .stat {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.budget-stats .label {
  color: var(--muted);
  font-size: 12px;
}

.budget-stats .value {
  font-weight: 700;
  font-size: 14px;
}

.progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  border-radius: 999px;
  transition: width 0.3s;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

/* ===== MODAL ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 40px var(--shadow);
  animation: modalFadeIn 0.3s;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.btn-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--line);
}

/* ===== DETAILS ===== */
.details {
  margin-top: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  padding: 4px 0;
}

.details summary:hover {
  color: var(--text);
}

.bullets {
  margin: 12px 0 0 20px;
  color: var(--muted);
  line-height: 1.8;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  margin-top: 40px;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

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

.tiny {
  font-size: 11px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .params-row {
    grid-template-columns: 1fr;
  }

  .invoice-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    width: 100%;
  }

  .tabs {
    top: 115px;
  }

  .budget-grid {
    grid-template-columns: 1fr;
  }
}
