*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  background: #f3f5f9;
  color: #222;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  padding: 1.5rem 2rem;
  background: linear-gradient(135deg, #004f9e, #00a4ff);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.app-header h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.6rem;
}

.app-header p {
  margin: 0;
  opacity: 0.9;
}

.app-main {
  flex: 1;
  padding: 1.5rem 2rem 2rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  padding: 0.75rem 2rem;
  background: #0b1b2b;
  color: #c9d4e2;
  font-size: 0.8rem;
}

/* Tabs */

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #d4dbe8;
}

.tab-button {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  border-radius: 0.5rem 0.5rem 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  color: #3a4a5f;
}

.tab-button.is-active {
  background: #ffffff;
  border-color: #d4dbe8;
  border-bottom: 1px solid #ffffff;
  font-weight: 600;
}

.tab-panel {
  display: none;
  background: #ffffff;
  border-radius: 0.5rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid #d4dbe8;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
}

.tab-panel.is-active {
  display: block;
}

/* Forms */

.form-grid {
  display: grid;
  gap: 1rem;
}

fieldset {
  border: 1px solid #e1e6f0;
  border-radius: 0.5rem;
  padding: 0.9rem 1rem 1rem;
}

legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #1f2937;
}

label {
  display: block;
  font-size: 0.85rem;
  color: #4b5563;
  margin-bottom: 0.3rem;
}

label input,
label select,
label textarea {
  display: block;
  width: 100%;
  margin-top: 0.15rem;
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
select,
textarea {
  padding: 0.45rem 0.5rem;
  border-radius: 0.35rem;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
  font-family: inherit;
}

input[type="color"] {
  padding: 0;
  border-radius: 0.35rem;
  border: 1px solid #d1d5db;
  height: 2rem;
  width: 4rem;
}

textarea {
  resize: vertical;
}

.two-col,
.three-col {
  display: grid;
  gap: 0.75rem;
}

.two-col {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.three-col {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

button {
  border-radius: 0.4rem;
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

button[type="submit"],
button[id^="btn-template"],
#btn-refresh-preview,
#btn-copy-signature,
#btn-export-xml,
#btn-contacts-export-csv {
  background: #2563eb;
  color: white;
  border-color: #1d4ed8;
}

button[type="submit"]:hover,
button[id^="btn-template"]:hover,
#btn-refresh-preview:hover,
#btn-copy-signature:hover,
#btn-export-xml:hover,
#btn-contacts-export-csv:hover {
  background: #1d4ed8;
}

button[type="button"] {
  background: #e5e7eb;
  color: #111827;
}

button[type="button"]:hover {
  background: #d1d5db;
}

/* Contacts table */

.contacts-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.contacts-count {
  font-size: 0.85rem;
  color: #4b5563;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: #f9fafb;
  border-radius: 0.5rem;
  overflow: hidden;
}

.contacts-table th,
.contacts-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e5e7eb;
}

.contacts-table th {
  background: #eef2ff;
  text-align: left;
  font-weight: 600;
  color: #111827;
}

.contacts-table tbody tr:nth-child(even) {
  background: #f3f4f6;
}

.contacts-table button {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
}

/* Preview */

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.preview-toolbar label {
  margin-bottom: 0;
}

.preview-note {
  font-size: 0.85rem;
  color: #4b5563;
  margin-bottom: 0.5rem;
  background: #eff6ff;
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  border: 1px solid #bfdbfe;
}

#signature-preview-wrapper {
  padding: 1rem;
  background: #e5e7eb;
  border-radius: 0.5rem;
  border: 1px dashed #9ca3af;
  margin-bottom: 0.75rem;
  overflow-x: auto;
}

.signature-preview {
  padding: 0.5rem;
  background: #ffffff;
  display: inline-block;
}

.signature-preview.is-clickable {
  cursor: pointer;
}

.signature-preview:active {
  transform: scale(0.996);
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.export-output {
  width: 100%;
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.8rem;
  padding: 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid #d1d5db;
  background: #f9fafb;
}

/* Responsive */

@media (max-width: 768px) {
  .app-main {
    padding: 1rem;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .preview-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}


/* Tab icons */
.tab-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.tab-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
}

.tab-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
  opacity: 0.9;
}

.inline-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.contacts-toolbar-left {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}


.subhead {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
}

.muted {
  color: #4b5563;
  font-size: 0.9rem;
  margin-top: 0;
}

#design-preview-wrapper {
  padding: 1rem;
  background: #e5e7eb;
  border-radius: 0.5rem;
  border: 1px dashed #9ca3af;
  overflow-x: auto;
  margin-bottom: 0.75rem;
}


/* Design tab: desktop two-column layout with sticky preview */
.template-layout {
  display: block;
}

.template-right {
  margin-top: 1rem;
}

@media (min-width: 992px) {
  .template-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1rem;
    align-items: start;
  }

  .template-right {
    margin-top: 0;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow: auto;
    padding-right: 0.25rem;
  }

  #design-preview-wrapper {
    margin-bottom: 0;
  }
}


.app-footer {
  margin-top: 2rem;
  padding: 1rem 0;
  text-align: center;
  border-top: 1px solid #e5e7eb;
}

.link-button {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.9rem;
}

.modal.is-hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-card {
  position: relative;
  max-width: 720px;
  margin: 5vh auto;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header, .modal-footer {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.modal-footer {
  border-top: 1px solid #e5e7eb;
  border-bottom: none;
  margin-top: auto;
}

.modal-body {
  padding: 1rem;
  overflow: auto;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
}


/* Footer + Legal modal (namespaced to avoid framework collisions) */
.app-footer {
  margin-top: 2rem;
  padding: 1rem 0;
  border-top: 1px solid #e5e7eb;
}

.app-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  color: #4b5563;
  font-size: 0.9rem;
}

.app-footer-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Modal */
.op-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
}

.op-modal[aria-hidden="false"] {
  display: block;
}

.op-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}

.op-modal-panel {
  position: relative;
  max-width: 760px;
  width: calc(100% - 2rem);
  margin: 6vh auto;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  overflow: hidden;
}

.op-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.op-modal-body {
  padding: 1rem;
  max-height: 72vh;
  overflow: auto;
}

.op-modal-close {
  border: none;
  background: #f3f4f6;
  width: 36px;
  height: 36px;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.legal-content {
  display: none;
}

.legal-content.is-active {
  display: block;
}
