:root {
  --bg: #0f1117;
  --panel: #151925;
  --panel-soft: #1a2030;
  --text: #f8fbff;
  --muted: #9aa6bd;
  --border: #293246;
  --accent: #5f7bff;
  --accent-glow: rgba(95, 123, 255, 0.42);
  --danger: #ff5f7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top right, rgba(95, 123, 255, 0.12), transparent 40%), var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.top-nav {
  background: #111;
  border-bottom: 1px solid #222;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
}

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
  border: 1px solid rgba(95, 123, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.top-link {
  color: #d8e2ff;
  text-decoration: none;
  font-size: 0.9rem;
}

.top-link:hover {
  text-decoration: underline;
}

.hero {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.2rem 1.25rem 0;
}

.hero h2 {
  margin: 0;
  font-size: 1.2rem;
}

.hero p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.app {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1440px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
}

.form-panel {
  padding: 1.35rem;
}

.panel-header h1 {
  margin: 0;
  font-size: 1.7rem;
}

.panel-header p {
  color: var(--muted);
  margin-top: 0.4rem;
}

.control-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.control-card h2 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
}

.field-group {
  margin-bottom: 1rem;
}

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

input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0.72rem 0.8rem;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.button-grid.two-col {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 0;
}

.items-header {
  margin-top: 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.items-header h2 {
  font-size: 1rem;
  margin: 0;
}

.items-container {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.65rem;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 140px 42px;
  gap: 0.55rem;
}

.btn {
  border: 0;
  cursor: pointer;
  border-radius: 10px;
  color: var(--text);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
  font-size: 0.87rem;
}

.btn:hover {
  transform: translateY(-1px) scale(1.01);
}

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

.btn-primary {
  width: 100%;
  margin-top: 1rem;
  padding: 0.92rem 1rem;
  background: linear-gradient(120deg, #4f66ff, #6f4fff);
  box-shadow: 0 10px 30px rgba(95, 123, 255, 0.32);
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 16px 34px rgba(95, 123, 255, 0.52);
  filter: brightness(1.05);
}

.btn-secondary,
.remove-item,
.file-btn {
  padding: 0.62rem 0.76rem;
  background: #242e45;
  border: 1px solid #33415e;
  text-align: center;
}

.remove-item {
  background: #302033;
  border-color: #4e314a;
  color: #ff9ab1;
}

.preview-panel {
  padding: 1.25rem;
  display: flex;
}

.invoice-preview {
  width: 100%;
  padding: 1.7rem;
  border-radius: 16px;
  background: #ffffff;
  color: #1b2231;
  min-height: 520px;
  border: 1px solid #e4ebf5;
  box-shadow: 0 14px 40px rgba(22, 29, 45, 0.08);
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
}

.template-modern {
  border-top: 8px solid #5f7bff;
}

.template-bold {
  border-top: 10px solid #111827;
  background: linear-gradient(180deg, #ffffff 0%, #f5f7ff 100%);
}

.invoice-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.preview-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 8px;
}

.hidden {
  display: none;
}

.invoice-meta p {
  margin: 0.15rem 0;
  color: #4a5568;
}

.invoice-party {
  margin-top: 1.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.invoice-party h3 {
  margin: 0;
  font-size: 0.84rem;
  letter-spacing: 0.02em;
  color: #60708b;
  text-transform: uppercase;
}

.invoice-party p {
  margin-top: 0.5rem;
  font-weight: 600;
}

#previewBusiness,
#previewClient {
  font-size: 1.02rem;
}

.table-wrap {
  margin-top: 1.2rem;
}

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

th,
td {
  text-align: left;
  padding: 0.72rem 0;
  border-bottom: 1px solid #e8eef7;
}

th:last-child,
td:last-child {
  text-align: right;
}

.totals-card {
  margin-top: 1.25rem;
  margin-left: auto;
  max-width: 300px;
  background: #f7faff;
  border: 1px solid #e4ebf8;
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.invoice-total-row,
.invoice-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.3rem 0;
}

.invoice-total-row span {
  color: #5b6b85;
}

.invoice-total-grand {
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid #dbe6f6;
  font-size: 1.05rem;
}

.saved-header {
  margin-top: 0;
}

.saved-invoices-list {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.6rem;
}

.saved-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.saved-item-main {
  border: 1px solid #33415e;
  background: #1a2235;
  color: #e9efff;
  border-radius: 10px;
  text-align: left;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
}

.saved-item-main strong,
.saved-item-main span {
  display: block;
}

.saved-item-main span {
  color: #a9b5cf;
  font-size: 0.8rem;
}

.empty-state {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.invoice-watermark {
  margin-top: auto;
  padding-top: 1.2rem;
  text-align: center;
  color: #8c96a8;
  font-size: 0.78rem;
  opacity: 0.65;
}

.site-footer {
  margin-top: 1rem;
  padding: 0.9rem 1.25rem 1.2rem;
  text-align: center;
  border-top: 1px solid #222;
  color: rgba(233, 239, 255, 0.6);
  font-size: 0.82rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: rgba(233, 239, 255, 0.85);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: #141d33;
  border: 1px solid #34466d;
  border-radius: 10px;
  padding: 0.72rem 1rem;
  color: #d5e1ff;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20;
}

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

.fade-in {
  animation: fadeIn 0.55s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 960px) {
  .top-nav {
    padding: 0.55rem 1rem;
  }

  .hero {
    padding: 1rem 1rem 0;
  }

  .app {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .form-panel,
  .preview-panel {
    padding: 1rem;
  }
}

@media (max-width: 640px) {
  .top-nav {
    min-height: 52px;
    padding: 0.45rem 0.8rem;
  }

  .brand {
    font-size: 0.95rem;
  }

  .brand-logo {
    width: 30px;
    height: 30px;
  }

  .top-link {
    font-size: 0.82rem;
  }

  .hero {
    padding: 0.85rem 0.8rem 0;
  }

  .hero h2 {
    font-size: 1.05rem;
  }

  .hero p {
    font-size: 0.86rem;
  }

  .field-row,
  .item-row,
  .invoice-party,
  .button-grid,
  .button-grid.two-col {
    grid-template-columns: 1fr;
  }

  .app {
    padding: 0.8rem;
    gap: 0.8rem;
  }

  .panel,
  .invoice-preview {
    border-radius: 14px;
  }

  .btn-primary,
  .btn-secondary,
  .file-btn {
    min-height: 46px;
  }

  .sticky-download {
    position: sticky;
    bottom: 0.6rem;
    z-index: 9;
  }

  .totals-card {
    max-width: 100%;
  }

  .site-footer {
    padding: 0.8rem;
    font-size: 0.76rem;
  }
}
