* {
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  margin: 0;
  background: #f2f5f9;
  color: #1e2630;
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.login-card h1 {
  margin-top: 0;
}

.login-error {
  margin: 0;
  color: #b42318;
  font-size: 0.92rem;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: #153b70;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.logged-in-user {
  font-size: 0.9rem;
  opacity: 0.95;
}

.logout-btn {
  width: auto;
  padding: 0.45rem 0.8rem;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
}

.menu-toggle,
.menu-close {
  width: auto;
  padding: 0.45rem 0.7rem;
  background: #0f2f59;
}

.menu-toggle:hover,
.menu-close:hover {
  background: #0a2444;
}

.side-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: #ffffff;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 40;
  padding: 1rem;
}

.side-menu.open {
  transform: translateX(0);
}

.side-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.side-menu-header h2 {
  margin: 0;
}

.menu-nav {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.menu-link {
  text-align: left;
}

.menu-language {
  display: grid;
  gap: 0.45rem;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  padding: 1rem;
}

.single-column {
  grid-template-columns: 1fr;
  max-width: 1100px;
  margin: 0 auto;
}

.page {
  display: none;
  gap: 1rem;
}

.page.active {
  display: grid;
}

.company-columns {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.wide {
  grid-column: 1 / -1;
}

h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.grid-form {
  display: grid;
  gap: 0.55rem;
}

.template-form-side {
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  padding-right: 0.25rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
}

.template-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 340px;
  gap: 1rem;
  align-items: start;
}

.a4-wrap {
  overflow: auto;
  border: 1px solid #d7e0ea;
  border-radius: 10px;
  padding: 0.7rem;
  background: #eef3f8;
}

.a4-editor {
  position: relative;
  width: 100%;
  max-width: 740px;
  aspect-ratio: 210 / 297;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #c7d3e0;
}

.a4-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.a4-guide {
  position: absolute;
  background: rgba(0, 0, 0, 0.28);
}

.a4-guide-v {
  top: 0;
  bottom: 0;
  width: 1px;
}

.a4-guide-h {
  left: 0;
  right: 0;
  height: 1px;
}

.a4-section {
  position: absolute;
  border: 1px solid #1f6ed4;
  background: rgba(31, 110, 212, 0.08);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}

.a4-section.active {
  border-width: 2px;
  box-shadow: 0 0 0 2px rgba(31, 110, 212, 0.2);
}

.a4-section-header {
  cursor: move;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(31, 110, 212, 0.18);
  padding: 0.25rem 0.35rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.a4-section-body {
  padding: 0.25rem 0.35rem;
  font-size: 0.72rem;
  color: #3d4d60;
}

.a4-section.is-logo-section {
  background: rgba(31, 110, 212, 0.04);
  border-style: dashed;
}

.a4-logo-preview {
  position: absolute;
  pointer-events: none;
  z-index: 4;
  object-fit: fill;
}

.data-sync-card {
  margin-top: 0.8rem;
}

.data-sync-card .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.file-import-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

hr {
  border: none;
  border-top: 1px solid #e3e8f0;
  margin: 0.4rem 0;
}

input,
textarea,
select,
button {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid #ced4dd;
  border-radius: 8px;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

button {
  background: #1f6ed4;
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: #155bb6;
}

button.secondary {
  background: #687788;
}

button.secondary:hover {
  background: #576476;
}

.meta {
  margin-top: 0;
  color: #43556c;
  font-size: 0.92rem;
}

.customer-select {
  cursor: pointer;
}

.customer-select.active {
  border-color: #1f6ed4;
  box-shadow: 0 0 0 2px rgba(31, 110, 212, 0.2);
}

.invoice-top-row {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 0.8rem;
}

.items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.items {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.item-label-row {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 3fr 1fr 1fr 1fr auto;
  font-size: 0.86rem;
  font-weight: 700;
  color: #43556c;
  margin-bottom: 0.35rem;
}

.item-row {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 3fr 1fr 1fr 1fr auto;
}

.item-row button {
  width: auto;
  padding: 0.6rem 0.8rem;
}

.invoice-summary {
  border-top: 1px solid #e6eaf0;
  border-bottom: 1px solid #e6eaf0;
  padding: 0.6rem 0;
  margin-bottom: 0.8rem;
}

.invoice-summary p {
  margin: 0.3rem 0;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.list-item {
  border: 1px solid #dde4ee;
  border-radius: 8px;
  padding: 0.65rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.list-item .meta {
  font-size: 0.9rem;
  color: #43556c;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
}

.row-actions button {
  width: auto;
}

.stats p {
  margin: 0.45rem 0;
}

@media (max-width: 720px) {
  .company-columns {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr;
  }

  .item-label-row {
    display: none;
  }

  .template-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0.8rem 1rem;
    flex-wrap: wrap;
  }

  .topbar-user {
    width: 100%;
    justify-content: space-between;
  }

  .topbar h1 {
    font-size: 1.05rem;
  }

  .side-menu {
    width: 100%;
  }
}
