:root {
  --navy: #0b2a4a;
  --navy-light: #16406d;
  --blue: #1d63b8;
  --blue-hover: #17529b;
  --gold: #f5c400;
  --green: #16794c;
  --green-hover: #11623d;
  --red: #c62828;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #d8e1eb;
  --text: #0f172a;
  --muted: #5b6878;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(11, 42, 74, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

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

.small {
  font-size: 0.82rem;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.92rem;
  max-width: 380px;
  border-left: 4px solid var(--gold);
}

.toast.success {
  background: #0f5132;
  border-left-color: #4ade80;
}

.toast.error {
  background: #842029;
  border-left-color: #f87171;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0b2a4a 0%, #16406d 55%, #1e5b94 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo {
  height: 44px;
  margin-bottom: 12px;
}

.login-brand h1 {
  font-size: 1.3rem;
  margin: 0 0 6px;
  color: var(--navy);
}

.login-brand p {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

/* ---------- Topbar ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  height: 30px;
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
}

.topbar-title {
  font-weight: 700;
  color: var(--navy);
  font-size: 1rem;
}

.topbar-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--navy);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: #eef3f9;
}

.nav-btn.active {
  background: var(--navy);
  color: #fff;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.user-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.user-role {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------- Layout & Cards ---------- */
.tab-panel {
  max-width: 1540px;
  margin: 0 auto;
  padding: 18px 20px 36px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #edf2f7;
}

.card-header h2,
.card-header h3 {
  margin: 0;
  color: var(--navy);
  font-size: 1.12rem;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(440px, 640px);
  gap: 20px;
  align-items: start;
}

.form-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 12px;
}

.grid-2-uneven {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  align-items: start;
}

/* ---------- Inputs & Buttons ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.84rem;
  font-weight: 600;
  color: #334155;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.93rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 99, 184, 0.15);
}

textarea {
  resize: vertical;
  min-height: 68px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label {
  margin: 0;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--navy);
  border-left: 3px solid var(--gold);
  padding-left: 8px;
}

.collapsible-box {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  background: #f8fafc;
}

.collapsible-box summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--navy);
}

.collapsible-content {
  margin-top: 10px;
}

.point-box {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafcff;
}

.point-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.point-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.point-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 3px;
}

.save-stamp {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--green);
}

.btn-xs {
  padding: 4px 9px;
  font-size: 0.78rem;
  border-radius: 6px;
}

.contact-pick-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.contact-pick-row select,
.contact-pick-row input {
  flex: 1;
}

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.contact-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 0.84rem;
}

.contact-chip-main {
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.contact-chip-email {
  font-weight: 600;
  color: var(--navy);
}

.contact-chip-label {
  font-size: 0.76rem;
  color: var(--muted);
}

.point-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--navy);
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  user-select: none;
}

.checkbox-pill input {
  width: 15px;
  height: 15px;
  accent-color: var(--navy);
  cursor: pointer;
}

.char-hint {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 3px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-primary {
  background: var(--blue);
  color: #fff;
}

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

.btn-navy {
  background: var(--navy);
  color: #fff;
}

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

.btn-success {
  background: var(--green);
  color: #fff;
}

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

.btn-outline {
  background: #fff;
  color: var(--navy);
  border-color: #cbd5e1;
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: #e2e8f0;
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--text);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 0.96rem;
}

.btn-full {
  width: 100%;
}

.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
}

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

.email-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.alert-ok {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

/* ---------- Live A4 Preview ---------- */
.preview-sticky {
  position: sticky;
  top: 72px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.preview-badge {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--navy);
}

.preview-fit-ok {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--green);
  background: #ecfdf5;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #a7f3d0;
}

.a4-viewport {
  background: #dbe4ee;
  padding: 14px;
  border-radius: var(--radius);
  display: flex;
  justify-content: center;
}

/* Exact A4 aspect ratio (210 / 297 = 0.707) */
.a4-sheet {
  width: 100%;
  max-width: 595px;
  aspect-ratio: 210 / 297;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.2);
  padding: 3.2% 5.7% 2.5%;
  display: flex;
  flex-direction: column;
  color: #111;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10.5px;
  position: relative;
  overflow: hidden;
}

.a4-top-email {
  text-align: center;
  color: #737373;
  font-weight: 700;
  font-size: 12px;
  text-decoration: underline;
  margin-bottom: 8px;
}

.a4-header-box {
  display: grid;
  grid-template-columns: 21% 64% 15%;
  border: 1px solid #222;
  margin-bottom: 12px;
}

.a4-col-logo {
  border-right: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.a4-col-logo img {
  width: 90%;
  height: auto;
  object-fit: contain;
}

.a4-col-title {
  border-right: 1px solid #222;
  text-align: center;
  padding: 5px 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.a4-main-title {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.01em;
}

.a4-week-line {
  font-weight: 700;
  font-size: 11px;
}

.a4-week-val {
  display: inline-block;
  min-width: 34px;
  border-bottom: 1px dotted #333;
  color: var(--navy);
}

.a4-order-line {
  font-size: 9.8px;
}

.a4-col-date {
  display: flex;
  flex-direction: column;
  text-align: center;
}

.a4-date-label {
  border-bottom: 1px solid #222;
  padding: 4px 2px;
  font-weight: 700;
  font-size: 9.3px;
  line-height: 1.2;
}

.a4-date-val {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 9.5px;
  color: var(--navy);
}

.a4-meta {
  font-size: 10px;
  line-height: 1.45;
  margin-bottom: 10px;
}

.a4-meta-gap {
  margin-top: 4px;
}

.a4-inspectors-row {
  margin-top: 6px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.a4-dotted-inline {
  flex: 1;
  border-bottom: 1.2px dotted #333;
  min-height: 14px;
  padding: 0 4px;
}

.a4-hand-val {
  color: #0f234b;
  font-weight: 500;
}

.a4-sections {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}

.a4-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 14px;
  padding-right: 48px;
  margin-bottom: 3px;
  font-size: 10px;
}

.a4-checkbox {
  width: 12px;
  height: 12px;
  border: 1.2px solid #222;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}

.a4-lines-wrap {
  position: relative;
  height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: 14px;
}

.a4-dotted-line {
  border-bottom: 1.2px dotted #333;
  width: 100%;
}

.a4-line-text {
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  font-size: 9.6px;
  line-height: 18.5px;
  color: #0f234b;
  white-space: pre-wrap;
  overflow: hidden;
  max-height: 55px;
  word-break: break-word;
}

.a4-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 10px;
  padding: 0 42px 0 4px;
}

.a4-sig-label {
  font-size: 10px;
  margin-bottom: 18px;
}

.a4-sig-line {
  border-bottom: 1.2px dotted #333;
  min-height: 15px;
  padding: 0 4px;
}

.a4-sig-sub {
  font-style: italic;
  font-size: 8.6px;
  margin-top: 2px;
  color: #333;
}

.a4-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 4px;
}

.a4-hashtag {
  font-weight: 700;
  font-size: 10.5px;
  padding-left: 10px;
  padding-bottom: 4px;
}

.a4-saur-logo {
  width: 34px;
  height: auto;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.data-table th {
  background: #f8fafc;
  color: var(--navy);
  font-weight: 700;
  white-space: nowrap;
}

.empty-cell {
  text-align: center !important;
  color: var(--muted);
  padding: 24px !important;
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-saved {
  background: #eff6ff;
  color: #1d4ed8;
}

.status-sent {
  background: #ecfdf5;
  color: #047857;
}

.status-inactive {
  background: #fef2f2;
  color: #b91c1c;
}

.action-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- Mobile Mode Switcher & Responsive ---------- */
.mobile-mode-bar {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: #e2e8f0;
  padding: 5px;
  border-radius: 10px;
  margin-bottom: 14px;
  position: sticky;
  top: 60px;
  z-index: 90;
}

.mobile-mode-btn {
  border: none;
  background: transparent;
  color: var(--navy);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.mobile-mode-btn.active {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 2px 6px rgba(11, 42, 74, 0.12);
}

@media (max-width: 1080px) {
  .mobile-mode-bar {
    display: grid;
  }

  .editor-grid,
  .grid-2-uneven {
    grid-template-columns: 1fr;
  }

  .editor-grid.mobile-show-form .preview-column {
    display: none;
  }

  .editor-grid.mobile-show-preview .form-column {
    display: none;
  }

  .preview-sticky {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .topbar-subtitle {
    display: none;
  }

  .topbar-nav {
    width: 100%;
    order: 3;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-btn {
    white-space: nowrap;
    padding: 9px 12px;
    font-size: 0.86rem;
  }

  .tab-panel {
    padding: 12px 10px 32px;
  }

  .card {
    padding: 14px;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  /* Prevent iOS Safari zoom on input focus & ensure 44px touch targets */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .checkbox-pill {
    padding: 7px 12px;
    font-size: 0.88rem;
  }

  .checkbox-pill input {
    width: 18px;
    height: 18px;
  }

  .save-bar,
  .pdf-actions,
  .email-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .save-bar .btn,
  .pdf-actions .btn,
  .email-actions .btn {
    width: 100%;
    min-height: 46px;
  }

  .a4-viewport {
    padding: 6px;
  }
}
