:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --yellow: #ffe066;
  --gray: #f1f3f6;
  --border: #c9d1dc;
  --text: #1a1a1a;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--gray);
}

/* Navigation */
.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--navy);
  color: #fff;
  padding: 12px 24px;
}
.topnav a {
  color: #fff;
  text-decoration: none;
  margin-left: 16px;
}
.topnav .brand {
  font-weight: bold;
  font-size: 18px;
  margin-left: 0;
}
.navlinks a:hover {
  text-decoration: underline;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 24px;
}
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}

.form-panel {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.form-panel h2 {
  margin-top: 20px;
  color: var(--navy);
  font-size: 16px;
}
fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 12px 0;
  padding: 12px;
}
legend {
  padding: 0 6px;
  font-weight: bold;
  color: var(--navy-2);
}

label {
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}
input,
textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}
input:focus,
textarea:focus {
  outline: 2px solid var(--navy-2);
  border-color: var(--navy-2);
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Item table (form) */
.item-input {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.item-input th,
.item-input td {
  border: 1px solid var(--border);
  padding: 4px;
}
.item-input th {
  background: var(--navy);
  color: #fff;
  font-weight: 600;
}
.item-input input {
  padding: 4px;
  font-size: 13px;
}
.item-total {
  font-weight: bold;
  text-align: right;
  padding-right: 8px;
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
}
.btn-primary {
  background: var(--navy);
  color: #fff;
}
.btn-primary:hover {
  background: var(--navy-2);
}
.btn-secondary {
  background: #e2e6ec;
  color: var(--navy);
}
.btn-danger {
  background: #b00020;
  color: #fff;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.status-msg {
  min-height: 20px;
  font-size: 13px;
}
.status-msg.error {
  color: #b00020;
}
.status-msg.ok {
  color: #1a7a3c;
}

/* Summary */
.summary {
  margin-top: 12px;
  font-size: 14px;
}
.summary div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

/* ================= PREVIEW ================= */
.preview-panel {
  background: #fff;
  padding: 28px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  font-size: 12px;
}
.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 3px solid var(--navy);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.invoice-header h1 {
  font-size: 18px;
  color: var(--navy);
  margin: 0;
  flex: 1;
  text-align: center;
}
.logo {
  font-size: 20px;
  font-weight: bold;
  color: var(--navy);
}
.invoice-no {
  text-align: right;
  font-size: 12px;
  background: var(--yellow);
  padding: 6px;
}

.invoice-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.invoice-meta .box {
  border: 1px solid var(--border);
  padding: 10px;
  background: var(--yellow);
}
.invoice-meta h3 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--navy);
}

.preview-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 11px;
}
.preview-items th,
.preview-items td {
  border: 1px solid var(--navy);
  padding: 5px;
}
.preview-items th {
  background: var(--navy);
  color: #fff;
  font-weight: 600;
}
.preview-items td.num {
  text-align: right;
}

.warranty {
  font-size: 11px;
  margin: 4px 0 12px;
}

.totals-block {
  margin-left: auto;
  width: 320px;
  font-size: 12px;
}
.totals-block div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.totals-block .grand {
  background: var(--navy);
  color: #fff;
  padding: 8px;
  font-weight: bold;
  border: none;
  margin-top: 4px;
}

.bank-block {
  margin-top: 20px;
  border-top: 2px dashed var(--border);
  padding-top: 12px;
  font-size: 11px;
}
.bank-block h3 {
  color: var(--navy);
  margin: 0 0 8px;
  font-size: 12px;
}
.bank-block p {
  margin: 2px 0;
}

.sign-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 40px;
  font-size: 11px;
}
.sig-box p {
  margin-bottom: 30px;
}
.sig-line {
  border-top: 1px solid var(--text);
}

/* History */
.history-panel {
  max-width: 1100px;
  margin: 24px auto;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
}
#searchInput {
  margin-bottom: 16px;
  max-width: 400px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th,
.history-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}
.history-table th {
  background: var(--navy);
  color: #fff;
}
.history-table button {
  padding: 4px 8px;
  font-size: 12px;
  margin-right: 4px;
}

/* ============ PRINT ============ */
@media print {
  body {
    background: #fff;
  }
  .no-print,
  .topnav,
  .form-panel,
  .actions,
  .history-panel {
    display: none !important;
  }
  .layout {
    display: block;
    padding: 0;
    gap: 0;
  }
  .preview-panel {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    width: 100%;
  }
  @page {
    size: A4;
    margin: 12mm;
  }
}
