* {
  box-sizing: border-box;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}

body {
  margin: 0;
  background: #f4f5f7;
  color: #1f2430;
}

.container {
  max-width: 1400px;
  width: min(100%, 1400px);
  margin: 0 auto;
  padding: 32px 24px 80px;
  position: relative;
}

.page-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  margin-bottom: 12px;
  min-height: 48px;
}

.header-actions {
  position: absolute;
  top: 0;
  right: 0;
}

button.button-red {
  background: #c92a2a;
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
}

button.button-red:hover {
  background: #a21f1f;
}

#shutdown-status {
  margin-top: 8px;
  color: #b00;
}

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

h2 {
  font-size: 1.1rem;
  margin-top: 28px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 20px;
  background: #fff;
  padding: 24px;
  border-radius: 14px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: none;
  align-items: stretch;
}

label {
  font-weight: 700;
  font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
input[type="month"],
select {
  padding: 14px 16px;
  border: 1px solid #ccd0d8;
  border-radius: 12px;
  font-size: 1.05rem;
  width: 100%;
}

form > div {
  width: 100%;
  display: block;
}

form > div > label,
form > div > input,
form > div > select,
form > div > div {
  width: 100%;
}

input[type="month"] {
  max-width: 240px;
}

select {
  min-height: 56px;
  appearance: none;
  background-color: #f9fafb;
  background-image: linear-gradient(45deg, transparent 50%, #1f2430 50%), linear-gradient(135deg, #1f2430 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(1.25em + 2px), calc(100% - 12px) calc(1.25em + 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .container {
    padding: 18px 14px 32px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  h1 {
    font-size: 1.35rem;
  }

  h2 {
    font-size: 1rem;
  }

  .pdf-frame {
    height: 45vh;
  }

  .signature-pad {
    height: 220px;
  }

  .actions {
    flex-direction: column;
    gap: 12px;
  }

  button,
  input[type="text"],
  input[type="email"],
  input[type="file"],
  input[type="month"],
  select {
    font-size: 1rem;
  }
}

@media (max-width: 520px) {
  .container {
    padding: 14px 12px 24px;
  }

  .pdf-frame {
    height: 40vh;
  }

  .signature-pad {
    height: 180px;
  }

  button,
  input[type="text"],
  input[type="email"],
  input[type="file"],
  input[type="month"],
  select {
    width: 100%;
  }
}

small {
  color: #6b7280;
  display: block;
  margin-top: -8px;
}

/* Improve spacing for name + email in document lists */
.tab-content td small,
table td small {
  display: block;
  margin-top: 6px;
  color: #6b7280;
  font-size: 0.85rem;
  line-height: 1.2;
}

/* Tunnel status spacing (make the help text separate from the URL input) */
#tunnel-status {
  display: block;
  margin-top: 8px;
  color: #6b7280;
  font-size: 0.9rem;
}

button {
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 120px;
}

button#clear {
  background: #6b7280;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.pdf-frame {
  width: 100%;
  height: 65vh;
  border: 1px solid #ccd0d8;
  border-radius: 8px;
  margin-top: 12px;
  background: #fff;
}

.signature-pad {
  width: 100%;
  height: 200px;
  border: 2px dashed #9aa1ad;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #eee;
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.pending { background: #fef3c7; color: #92400e; }
.badge.signed { background: #d1fae5; color: #065f46; }

/* Spinner overlay while processing signature */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.overlay .panel {
  background: #fff;
  padding: 20px 24px;
  border-radius: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #e6edf8;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .message { font-weight: 600; color: #111827; }

/* Tabs for monthly grouping */
.tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 18px;
  flex-wrap: wrap;
}
.tab-btn {
  background: #eef2ff;
  border: 1px solid #dbeafe;
  color: #1f2937;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
.tab-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #1e40af;
}
.tab-content table { margin-top: 8px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10000;
}

.modal-card {
  width: min(420px, calc(100% - 32px));
  background: #ffffff;
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.modal-spinner {
  width: 42px;
  height: 42px;
  border: 5px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.modal-actions {
  display: flex;
  justify-content: center;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-card p {
  margin: 0;
  color: #1f2937;
  line-height: 1.5;
}

