/* =========================================================================
   E2E vCard Sharing — Stylesheet
   ========================================================================= */

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

:root {
  --bg:          #f5f5f5;
  --surface:     #ffffff;
  --border:      #e0e0e0;
  --text:        #1a1a1a;
  --text-muted:  #6b7280;
  --primary:     #2563eb;
  --primary-h:   #1d4ed8;
  --danger:      #dc2626;
  --danger-h:    #b91c1c;
  --success:     #16a34a;
  --warning:     #d97706;
  --radius:      10px;
  --shadow:      0 1px 4px rgba(0,0,0,.10);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.top-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.top-bar-actions { display: flex; gap: 8px; align-items: center; }

.logo { font-weight: 700; font-size: 16px; letter-spacing: -.3px; }

.screen { flex: 1; padding: 32px 24px; max-width: 1100px; margin: 0 auto; width: 100%; }

.hidden { display: none !important; }

/* ── Cards / panels ──────────────────────────────────────────────────────── */

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

.card-panel.centered { text-align: center; max-width: 480px; margin: 60px auto; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Form fields ─────────────────────────────────────────────────────────── */

.field-group { margin-bottom: 14px; }

.field-group label,
.dynamic-list > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field-group { flex: 1; }

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="url"],
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

textarea { resize: vertical; }

.req { color: var(--danger); }

/* ── Dynamic list rows (tel / email / org / title / url / note) ──────────── */

.field-section { margin-bottom: 14px; }

.dynamic-list { margin-bottom: 6px; }

.dynamic-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}

.dynamic-row .dynamic-input { flex: 1; }

.dynamic-type-select {
  flex-shrink: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
  outline: none;
}

.dynamic-type-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-h); }

.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled)   { background: var(--danger-h);  }

.btn-ghost    { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg); }

@keyframes btn-flash {
  0%, 100% { background: transparent; color: var(--text); box-shadow: none; }
  50%      { background: var(--warning); color: #fff; box-shadow: 0 0 0 3px rgba(217,119,6,.35); }
}
.btn-flash {
  animation: btn-flash 1s ease-in-out infinite;
}

.btn-sm  { padding: 5px 12px; font-size: 13px; }
.btn-lg  { padding: 12px 28px; font-size: 16px; }

/* ── Editor actions ──────────────────────────────────────────────────────── */

.editor-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.status-msg { font-size: 13px; }
.status-msg.success { color: var(--success); }
.status-msg.error   { color: var(--danger);  }

/* ── Share form ──────────────────────────────────────────────────────────── */

.share-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.share-form input { flex: 1; }

/* ── Recipient rows ──────────────────────────────────────────────────────── */

.recipient-list { display: flex; flex-direction: column; gap: 8px; }

.recipient-row {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.recipient-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  gap: 8px;
}

.recipient-info { flex: 1; min-width: 0; }

.recipient-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recipient-meta {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.recipient-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Anomaly badge ──────────────────────────────────────────────────── */

.anomaly-badge {
  display: inline-block;
  margin-left: 6px;
  color: var(--warning);
  font-size: 13px;
  cursor: default;
  vertical-align: middle;
}

/* ── Recipient details panel (expandable) ──────────────────────────── */

.recipient-details {
  border-top: 1px solid var(--border);
  padding: 16px 14px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.details-section {
  flex: 1;
  min-width: 220px;
}

.details-section h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.details-section .field-group {
  margin-bottom: 10px;
}

.details-section .field-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 4px;
}

.details-section input[type="text"] {
  font-size: 13px;
  padding: 6px 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.details-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ── Access history table ────────────────────────────────────────────── */

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.history-table th {
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.ua-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

.history-empty {
  font-size: 13px;
  margin: 0;
}

/* ── Share modal ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.modal h3 { font-size: 18px; margin-bottom: 8px; }

.share-url-box {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.share-url-box input {
  flex: 1;
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.qr-container {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

.vcard-qr-section {
  margin-top: 28px;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

.vcard-qr-label {
  font-size: 13px;
  margin-bottom: 12px;
}

.vcard-qr-section .qr-container svg {
  max-width: 220px;
  width: 100%;
  height: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ── Contact card (recipient view) ──────────────────────────────────────── */

.contact-card { max-width: 500px; margin: 40px auto; }

.contact-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.contact-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.contact-card h1 { font-size: 22px; font-weight: 700; }
.contact-subtitle { font-size: 14px; margin-top: 2px; }

.contact-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.contact-field {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.field-icon { font-size: 18px; line-height: 1.4; flex-shrink: 0; }

.field-value { font-size: 14px; word-break: break-word; }

.field-value a { color: var(--primary); text-decoration: none; }
.field-value a:hover { text-decoration: underline; }

.card-actions { text-align: center; margin-bottom: 20px; }

.update-hint { font-size: 12px; text-align: center; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Setup screen ────────────────────────────────────────────────────────── */

#screen-setup .card-panel {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
}

#screen-setup h2 { font-size: 20px; margin-bottom: 12px; }

#screen-setup p { margin-bottom: 24px; }

.setup-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.setup-divider::before,
.setup-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */

.muted        { color: var(--text-muted); }
.error-icon   { font-size: 48px; margin-bottom: 12px; }
.error        { color: var(--danger); }

/* ── Cards list screen (Phase 3) ─────────────────────────────────────────── */

.cards-screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.cards-screen-header h2 { font-size: 20px; font-weight: 700; }

.cards-screen-actions { display: flex; gap: 8px; align-items: center; }

.cards-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-list-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow);
}

.card-list-info { flex: 1; min-width: 0; }

.card-list-name {
  display: block;
  font-weight: 700;
  font-size: 16px;
}

.card-list-meta {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-list-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn-card-rename {
  padding: 2px 6px;
  font-size: 12px;
  vertical-align: middle;
  margin-left: 4px;
  opacity: 0.5;
}
.btn-card-rename:hover { opacity: 1; }

.card-rename-input {
  font-size: 16px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--primary);
  width: 180px;
  font-family: inherit;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .two-col { grid-template-columns: 1fr; }
  .screen  { padding: 16px; }
  .panel   { padding: 20px; }
  .card-panel { padding: 20px; }
  .card-list-row { flex-wrap: wrap; }
  .card-list-actions { width: 100%; justify-content: flex-end; }
}
