/* Modern Mobile-First Styles for Kai Electrical CoT System (100% English UI) */
:root {
  --primary: #00a859;
  --primary-hover: #008f4c;
  --primary-light: #e6f7ef;
  --primary-border: #80d4ac;
  --bg-page: #f1f5f9;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --radius-lg: 12px;
  --radius-md: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: 24px;
  -webkit-text-size-adjust: 100%;
}

/* Header */
.top-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 10px 16px;
}

.header-container {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-img {
  height: 42px;
  width: auto;
  object-fit: contain;
}

.header-badges {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  line-height: 1.3;
}

.header-badges strong {
  color: var(--primary);
  font-size: 13px;
}

/* Navigation Tabs */
.nav-tabs {
  max-width: 960px;
  margin: 10px auto 0;
  padding: 0 16px;
  display: flex;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  padding: 9px 8px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 168, 89, 0.25);
}

/* Layout */
.container {
  max-width: 960px;
  margin: 14px auto 0;
  padding: 0 16px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}

.badge-eso {
  background: var(--primary-light);
  color: var(--primary-hover);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
}

/* Form Controls - Standard 16px font-size to prevent iOS Safari auto-zoom/scaling */
.form-group {
  margin-bottom: 14px;
  min-width: 0;
  width: 100%;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

.form-label .req {
  color: #ef4444;
  margin-left: 2px;
}

.form-label .opt {
  color: #94a3b8;
  font-weight: 400;
  font-size: 12px;
  margin-left: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px !important; /* Critical: 16px prevents iOS Safari zoom and unifies input vs select sizing */
  font-family: inherit;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text-main);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  line-height: 1.4;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 89, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

/* Standardize iOS autofill appearance */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0px 1000px #ffffff inset !important;
  font-size: 16px !important;
}

/* Date input mobile overflow fixes */
input[type="date"], .date-input-control {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  min-height: 44px;
  font-size: 16px !important;
  background-color: #ffffff;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

/* Grids with min-width: 0 to prevent mobile overflow */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.grid-2 > .form-group {
  min-width: 0;
  max-width: 100%;
}

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

.grid-name {
  display: grid;
  grid-template-columns: 120px 1fr 1fr;
  gap: 10px;
  min-width: 0;
}

@media (max-width: 600px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .grid-name {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .grid-name .title-group {
    grid-column: span 2;
  }
}

/* Radio Group */
.radio-group {
  display: flex;
  gap: 10px;
}

@media (max-width: 500px) {
  .radio-group {
    flex-direction: column;
  }
}

.radio-card {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: #ffffff;
  transition: all 0.15s ease;
}

.radio-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.radio-card input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--primary);
}

/* Autocomplete Container */
.autocomplete-container {
  position: relative;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}

.autocomplete-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.1s;
}

.autocomplete-item:hover, .autocomplete-item:active {
  background: var(--primary-light);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

/* Presets Chips */
.presets-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-chip {
  padding: 6px 12px;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.preset-chip:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
  color: var(--primary);
}

/* Signature Pad */
.signature-box {
  border: 1.5px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
  padding: 8px;
  margin-bottom: 8px;
}

.signature-canvas {
  width: 100%;
  height: 120px;
  display: block;
  touch-action: none;
  background: #ffffff;
  cursor: crosshair;
}

.signature-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}

.btn-link {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}

/* Form Action Button (In-Flow, bottom of form) */
.form-action-section {
  margin-top: 20px;
  margin-bottom: 24px;
}

.btn-share-primary {
  width: 100%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 3px 6px rgba(0, 168, 89, 0.35);
  transition: background 0.15s, transform 0.1s;
}

.btn-share-primary:active {
  transform: scale(0.98);
}

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

.btn-secondary {
  background: #ffffff;
  color: #334155;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

/* History List */
.history-item {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.15s;
}

.history-item:hover {
  border-color: var(--primary);
}

.history-info-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.history-info-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.btn-icon {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  color: #334155;
}

.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

/* Preset Editor in Settings */
.preset-edit-card {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
}

.preset-edit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.preset-edit-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

/* Legal Notice */
.legal-box {
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  font-size: 11px;
  color: #475569;
  line-height: 1.4;
  margin-top: 10px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  display: none;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Dedicated PIN Authorization View (In-Flow, DOM Separated) */
.pin-view-container {
  min-height: 75vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.pin-modal-card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  padding: 26px 20px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.pin-logo {
  margin-bottom: 12px;
}

.pin-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
}

.pin-subtitle {
  font-size: 12px;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 12px;
}

.pin-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 14px;
}

.pin-input-field {
  font-size: 18px !important;
  text-align: center;
  letter-spacing: 2px;
  font-weight: 600;
  padding: 12px;
}

.pin-error-msg {
  color: #ef4444;
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  text-align: center;
}

.pin-footer-note {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
  margin-top: 14px;
}

/* Progressive PIN Lockout Card */
.pin-lockout-card {
  background: #fef2f2;
  border: 1.5px solid #f87171;
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 12px;
  margin-bottom: 8px;
  text-align: center;
}

.lockout-title {
  color: #b91c1c;
  font-weight: 700;
  font-size: 14px;
}

.lockout-desc {
  color: #7f1d1d;
  font-size: 12px;
  margin-top: 4px;
}

.lockout-timer {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 24px;
  font-weight: 800;
  color: #dc2626;
  margin-top: 6px;
  letter-spacing: 1px;
}
