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

@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined');


body {
  font-family: 'Poppins', sans-serif;
  margin: 0;
  padding: 0;
  background: #222;
  color: #eee;
  overflow-x: hidden;
}

/* Top navigation bar */
nav {
  display: flex;
  gap: 1.5rem;
  background: #222;
  padding: 1rem 2rem;
  border-bottom: 1px solid #333;
  border-radius: 12px;
  margin-bottom: 2rem;
  box-sizing: border-box;
}

/* Nav links */
nav a {
  text-decoration: none;
  color: #aaa;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
}

/* Hover / focus effect */
nav a:hover,
nav a:focus {
  background: #2e2e2e;
  border-color: #444;
  color: #eee;
  outline: none;
}

/* Active page link */
nav a.active {
  background: #2e2e2e;
  border-color: #444;
  color: #F7E730;
}

section {
  width: 70%;
  margin: 2rem auto;
  max-width: 1500px;
}

/* Headings */
h1, h2, h3 {
  margin: 0 0 1rem 0;
  font-weight: 700;
}

h1 {
  font-size: 2.7rem;
}

/* Form container */
.form {
  width: 100%;
  margin: 1rem 0;
  color: #eee;
  box-sizing: border-box;
}

/* Form items */
.form .item {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
}

.form label {
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: #999;
}

/* Inputs and modern selects */
.form input,
.form textarea,
.form button[type="button"],
.form button[type="submit"],
.form button[type="cancel"] {
  padding: 0.8rem 0.6rem;
  font-size: 1rem;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  outline: none;
  background: #2a2a2a;
  color: #eee;
  transition: border 0.2s, background 0.2s, transform 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
  width: 100%;
}

.form input:focus,
.form textarea:focus {
  border-color: #F7E730;
}

.form button a {
  text-decoration: none;
  color: #eee;
}

.form select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  outline: none;
  background: #2a2a2a url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20,50 70,100 120,50' fill='none' stroke='%23aaaaaa' stroke-width='20' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.8rem center;
  background-size: 1rem;
  cursor: pointer;
  transition: border 0.2s;
  width: 100%;
  box-sizing: border-box;
  color: #eee;
}

.form select:focus {
  border-color: #F7E730;
}

/* Remove default arrow in IE */
.form select::-ms-expand {
  display: none;
}

/* Table styling */
#items {
  border: 1px solid #3a3a3a;
  border-radius: 30px;
  padding: 1rem;
  display: block;
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  table-layout: fixed;
  word-break: break-word;
}

#items thead {
  border-bottom: 1px solid #3a3a3a;
}

#items th,
#items td {
  padding: 0.8rem 0.4rem;
  text-align: left;
  overflow-wrap: break-word;
}

#items th {
  font-weight: 600;
  color: #999;
}

/* Inputs and selects inside table */
#items input,
#items select {
  width: 100%;
  box-sizing: border-box;
}

/* Column widths for table */
#items th:nth-child(1),
#items td:nth-child(1) { width: 15%; } /* Name */
#items th:nth-child(2),
#items td:nth-child(2) { width: 25%; } /* Description */
#items th:nth-child(3),
#items td:nth-child(3) { width: 10%; } /* Quantity */
#items th:nth-child(4),
#items td:nth-child(4) { width: 15%; } /* Units */
#items th:nth-child(5),
#items td:nth-child(5) { width: 17%; } /* Price */
#items th:nth-child(6),
#items td:nth-child(6) { width: 8%; } /* Remove button */

/* Buttons */
.form button[type="submit"] {
  background: #F7E730;
  color: #222;
  border: 1px solid #F7E730;
  font-weight: 600;
  cursor: pointer;
}

.form button[type="submit"]:hover {
  background: #ffe84d;
  border-color: #ffe84d;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(247, 231, 48, 0.3);
}

.form button[type="submit"]:active {
  transform: translateY(0);
  box-shadow: none;
}

.form button[type="button"]:hover {
  border-color: #555;
  background: #333;
  transform: translateY(-1px);
}

.form button[type="button"]:active {
  transform: translateY(0);
}

/* Two-button row */
.form .item.two {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Subtotal / total text */
.form .text-right {
  text-align: right;
  font-weight: 600;
  margin: 0.2rem 0;
}

.existing {
  display: block;
  width: 100%;
  margin-top: 1rem;
}

.existing thead {
  display: none;
}

.existing tbody {
  display: block;
}

/* Each row is a horizontal flex card */
.existing tbody tr {
  display: flex;
  align-items: center;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  gap: 0.75rem;
}

.existing tbody td {
  padding: 0;
  border: none;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Primary label — name, invoice number, client name */
.existing tbody td:first-child {
  flex: 2;
  font-weight: 600;
  font-size: 1rem;
}

/* Secondary info — client, date, amount, address, etc. */
.existing tbody td:not(:first-child):not(:last-child) {
  flex: 1;
  color: #888;
  min-width: 0;
}

/* Actions cell */
.existing tbody td:last-child {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  overflow: visible;
}

.existing td .row-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.existing td a {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem;
  border-radius: 50%;
  border: 1px solid #3a3a3a;
  text-decoration: none;
  color: #aaa;
  font-family: 'Material Symbols Outlined';
  font-size: 20px;
  box-sizing: border-box;
  transition: border 0.2s, background 0.2s, color 0.2s, transform 0.15s;
}

.existing td a:hover {
  border-color: #F7E730;
  color: #F7E730;
  background: #2e2e2e;
  transform: scale(1.1);
}

.existing td a:active {
  transform: scale(1);
}

/* Invoices table — number shrinks to content, client takes 30% */
#existing-invoices tbody td:nth-child(1) {
  flex: 0 0 auto;
}

#existing-invoices tbody td:nth-child(2) {
  flex: 0 0 30%;
  min-width: 0;
}


/* Existing invoices table */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

table th,
table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
}

table th {
  font-weight: 600;
  color: #777;
}

/* Two-column editor layout */
.editor-layout {
  display: flex;
  align-items: flex-start;
  margin: 2rem 0;
}

.editor-layout section {
  width: 55%;
  margin: 0;
  padding: 0 3rem;
  box-sizing: border-box;
}

.preview-col {
  position: fixed;
  top: 0;
  right: 0;
  width: 45%;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
  background: #f5f5f5;
  border-left: 1px solid #ddd;
}

.invoices-section {
  width: 55%;
  padding: 0 3rem;
  margin: 2rem 0;
  box-sizing: border-box;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  box-sizing: border-box;
}

.preview-wrapper {
  width: 100%;
}

.preview-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  padding: 0.65rem 1rem;
  margin: 0;
  border-bottom: 1px solid #ddd;
  position: sticky;
  top: 0;
  background: #f5f5f5;
  z-index: 1;
}

#invoice-preview {
  border: none;
  display: block;
  width: 100%;
  overflow: hidden;
}

/* Tablet */
@media (max-width: 900px) {
  section {
    width: 90%;
  }

  .preview-col {
    display: none;
  }

  .editor-layout {
    display: block;
    width: 90%;
    margin: 2rem auto;
  }

  /* Fill the editor-layout container fully and drop the desktop 3rem side padding */
  .editor-layout section {
    width: 100%;
    padding: 0;
    box-sizing: border-box;
  }

  .invoices-section {
    width: 90%;
    padding: 0;
    margin: 2rem auto;
  }
}

/* Mobile */
@media (max-width: 600px) {
  body {
    background: #1a1a1a;
  }

  /* Prevent iOS font zoom */
  input, select, textarea {
    font-size: 16px !important;
  }

  nav {
    border-radius: 0;
    margin-bottom: 0;
    padding: 0.6rem 0.75rem;
    gap: 0;
    justify-content: space-around;
    box-shadow: 0 1px 0 #333;
  }

  nav a {
    font-size: 0.85rem;
    border: none;
    padding: 0.4rem 0.75rem;
  }

  nav a:hover {
    background: transparent;
    border: none;
  }

  section {
    width: 100%;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
  }

  /* Stretch editor and invoices sections fully on mobile */
  .editor-layout {
    width: 100%;
    margin: 0;
  }

  .editor-layout section {
    padding: 1rem;
  }

  .invoices-section {
    width: 100%;
    padding: 1rem;
    margin: 0;
  }

  h1 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
  }

  h2 {
    font-size: 1.1rem;
  }

  .form {
    padding: 0;
    margin: 0 0 1rem 0;
  }

  .form .item {
    margin-bottom: 1rem;
  }

  /* Uppercase small labels */
  .form label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    margin-bottom: 0.3rem;
  }

  .form input,
  .form textarea,
  .form select {
    background: #2a2a2a;
    border-color: #3a3a3a;
    border-radius: 10px;
    padding: 0.75rem 0.6rem;
  }

  /* Yellow primary button */
  .form button[type="submit"] {
    background: #F7E730;
    color: #222;
    border-color: #F7E730;
    border-radius: 10px;
    font-weight: 600;
    padding: 0.85rem;
    width: 100%;
  }

  .form button[type="submit"]:hover {
    background: #e8d820;
    border-color: #e8d820;
  }

  .form button[type="button"] {
    border-radius: 10px;
    background: #2a2a2a;
    border-color: #3a3a3a;
  }

  .form .item.two {
    flex-direction: column;
    gap: 0.5rem;
  }

  .form .item.two button {
    width: 100%;
  }

  /* Items table — clean stacked cards */
  #items {
    border: none;
    border-radius: 0;
    padding: 0;
    width: 100%;
    display: block;
  }

  #items thead {
    display: none;
  }

  #items tbody {
    display: block;
    width: 100%;
  }

  #items tbody tr {
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.6rem;
    gap: 0.4rem;
  }

  #items td {
    display: block;
    width: 100% !important;
    padding: 0;
  }

  #items td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    display: block;
    margin-bottom: 0.2rem;
  }

  #items td:last-child {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.25rem;
  }

  #items input,
  #items select {
    background: #333;
    border-color: #444;
    border-radius: 8px;
    padding: 0.5rem;
  }

  /* Existing tables — switch to vertical stacked cards on mobile */
  .existing tbody tr {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
    gap: 0;
  }

  .existing tbody td {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .existing tbody td:first-child {
    flex: none;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0.2rem;
  }

  /* Secondary info — show label above value */
  .existing tbody td:not(:first-child):not(:last-child) {
    flex: none;
    width: 100%;
    box-sizing: border-box;
    color: #bbb;
    padding-top: 0.3rem;
  }

  .existing tbody td:not(:first-child):not(:last-child)::before {
    content: attr(data-label);
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    margin-bottom: 0.1rem;
  }

  .existing tbody td:last-child {
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    justify-content: flex-start;
    margin-top: 0.5rem;
  }

  .existing .row-actions {
    justify-content: flex-start;
  }

  .existing td a {
    padding: 0.4rem;
    font-size: 18px;
  }
}
