/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #2563eb;
  --blue-dark:  #1d4ed8;
  --blue-light: #eff6ff;
  --green:      #16a34a;
  --green-dark: #15803d;
  --red:        #dc2626;
  --red-light:  #fef2f2;
  --gray-50:    #f8fafc;
  --gray-100:   #f1f5f9;
  --gray-200:   #e2e8f0;
  --gray-300:   #cbd5e1;
  --gray-400:   #94a3b8;
  --gray-600:   #475569;
  --gray-700:   #334155;
  --gray-800:   #1e293b;
  --gray-900:   #0f172a;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  padding-bottom: 80px; /* space for sticky footer */
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== DRAFT BANNER ===== */
.draft-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #92400e;
}
.draft-banner-actions { display: flex; gap: 12px; }
.btn-text { background: none; border: none; font-size: 14px; font-weight: 600; cursor: pointer; padding: 0; }
.btn-danger { color: var(--red); }

/* ===== APP HEADER ===== */
.app-header {
  background: var(--blue);
  color: white;
  padding: 16px 16px 12px;
  position: relative;
}
.app-header h1 { font-size: 18px; font-weight: 700; }
.app-subheader { font-size: 13px; opacity: 0.85; margin-top: 2px; }

/* ===== FORM BODY ===== */
.form-body { padding: 12px 12px 0; }

.form-section {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-num {
  background: var(--blue);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.section-hint {
  font-size: 13px;
  color: var(--gray-400);
  margin-top: -8px;
  margin-bottom: 12px;
}

/* ===== FIELDS ===== */
.field-group { margin-bottom: 12px; }
.field-group:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 5px;
}
.day-label {
  color: var(--blue);
  font-weight: 500;
  margin-left: 2px;
}

input[type="text"],
input[type="date"],
input[type="number"],
select {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  font-size: 16px; /* prevents iOS auto-zoom */
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--gray-800);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

input.error, select.error {
  border-color: var(--red);
  background: var(--red-light);
}

.field-error {
  display: block;
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
  min-height: 16px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ===== PUBLICATION CARDS ===== */
.pub-card {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.pub-card-header {
  background: var(--gray-100);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pub-card-title { font-size: 13px; font-weight: 700; color: var(--blue); }

/* Distinct Colors for Publication Cards */
.pub-card:nth-child(6n+1) { border-color: #c7d2fe; }
.pub-card:nth-child(6n+1) .pub-card-header { background: #e0e7ff; }
.pub-card:nth-child(6n+1) .pub-card-title { color: #3730a3; }

.pub-card:nth-child(6n+2) { border-color: #bbf7d0; }
.pub-card:nth-child(6n+2) .pub-card-header { background: #dcfce7; }
.pub-card:nth-child(6n+2) .pub-card-title { color: #166534; }

.pub-card:nth-child(6n+3) { border-color: #fef08a; }
.pub-card:nth-child(6n+3) .pub-card-header { background: #fef3c7; }
.pub-card:nth-child(6n+3) .pub-card-title { color: #92400e; }

.pub-card:nth-child(6n+4) { border-color: #fed7aa; }
.pub-card:nth-child(6n+4) .pub-card-header { background: #ffedd5; }
.pub-card:nth-child(6n+4) .pub-card-title { color: #9a3412; }

.pub-card:nth-child(6n+5) { border-color: #fbcfe8; }
.pub-card:nth-child(6n+5) .pub-card-header { background: #fce7f3; }
.pub-card:nth-child(6n+5) .pub-card-title { color: #9d174d; }

.pub-card:nth-child(6n+6) { border-color: #e9d5ff; }
.pub-card:nth-child(6n+6) .pub-card-header { background: #f3e8ff; }
.pub-card:nth-child(6n+6) .pub-card-title { color: #581c87; }

.btn-remove-pub {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove-pub:hover { color: var(--red); }

.pub-card-body { padding: 14px; }

/* ===== COPY TYPE ROWS ===== */
.copy-type-row {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  position: relative;
}

.copy-type-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.copy-type-label { font-size: 12px; font-weight: 600; color: var(--gray-600); }

.btn-remove-copy {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove-copy:hover { color: var(--red); }

/* ===== PILL TOGGLE (Bundle / Loose) ===== */
.pill-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
  height: 44px;
}
.pill-option {
  background: white;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  height: 44px;
  transition: background 0.15s, color 0.15s;
}
.pill-option.active {
  background: var(--blue);
  color: white;
}
.pill-option:first-child { border-right: 1px solid var(--gray-200); }

/* Fields shown conditionally */
.bundle-fields.hidden, .loose-fields.hidden { display: none !important; }

/* ===== ADD BUTTONS ===== */
.btn-add-copy-type {
  width: 100%;
  background: none;
  border: 1.5px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  margin-top: 4px;
  min-height: 40px;
}
.btn-add-copy-type:hover { border-color: var(--blue); background: var(--blue-light); }

.btn-add-publication {
  width: 100%;
  background: none;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  color: var(--blue);
  font-size: 14px;
  font-weight: 600;
  padding: 14px;
  cursor: pointer;
  min-height: 52px;
}
.btn-add-publication:hover { border-color: var(--blue); background: var(--blue-light); }

/* ===== STICKY FOOTER ===== */
.sticky-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 12px env(safe-area-inset-bottom, 12px);
  background: white;
  border-top: 1px solid var(--gray-200);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  z-index: 50;
}

/* ===== BUTTONS ===== */
.btn-primary, .btn-success, .btn-secondary, .btn-red {
  height: 52px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary  { background: var(--blue);  color: white; }
.btn-success  { background: var(--green); color: white; }
.btn-red      { background: var(--red);   color: white; }
.btn-secondary { background: white; border: 1.5px solid var(--gray-200); color: var(--gray-700); }
.btn-full { width: 100%; display: block; }
.btn-primary:active, .btn-success:active, .btn-red:active { transform: scale(0.98); }

.btn-back {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  padding: 0 8px;
}

/* ===== PREVIEW SCREEN ===== */
#screen-preview .app-header { text-align: center; }
#screen-preview .app-header h1 { padding-left: 70px; padding-right: 70px; }
.preview-body { padding: 12px 12px 0; }

.preview-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.preview-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.preview-card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview-stat {}
.preview-stat-label { display: block; font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }
.preview-stat-value { display: block; font-size: 20px; font-weight: 700; color: var(--gray-800); }

/* ===== PUBLICATIONS PREVIEW TABLE ===== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 560px;
}
thead tr { border-bottom: 2px solid var(--gray-200); }
th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
td { padding: 10px 10px; border-bottom: 1px solid var(--gray-100); color: var(--gray-800); }
tfoot td { border-top: 2px solid var(--gray-200); border-bottom: none; }
.total-label { font-weight: 700; color: var(--gray-600); font-size: 13px; }
.total-value { font-weight: 700; font-size: 16px; color: var(--blue); text-align: right; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}
.badge-bundle { background: #dbeafe; color: #1d4ed8; }
.badge-loose  { background: #d1fae5; color: #065f46; }

.dash { color: var(--gray-300); }

/* ===== SUBMIT ERROR ===== */
.submit-error {
  background: var(--red-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  text-align: center;
  color: var(--red);
}
.submit-error p { margin-bottom: 10px; font-size: 14px; }

/* ===== SUCCESS SCREEN ===== */
.success-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}
.success-icon {
  width: 72px;
  height: 72px;
  background: var(--green);
  color: white;
  border-radius: 50%;
  font-size: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.success-body h2 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.success-sub { color: var(--gray-400); font-size: 15px; margin-bottom: 24px; }
.submission-id-box {
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-bottom: 28px;
  width: 100%;
  max-width: 280px;
}
.submission-id-label { display: block; font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.submission-id-value { display: block; font-size: 22px; font-weight: 700; font-family: monospace; color: var(--blue); }

/* ===== DESKTOP ADJUSTMENTS ===== */
@media (min-width: 600px) {
  body { max-width: 480px; margin: 0 auto; }
  .sticky-footer { max-width: 480px; left: 50%; transform: translateX(-50%); }
}
