/**
 * Kirago — campos de formulário unificados (login + modais)
 * Mantém a paleta existente; melhora superfície, foco e ritmo visual.
 */

/* ── Variáveis locais (mesmas cores do tema) ───────────────── */
body.kirago-theme {
  --kg-field-bg: rgba(0, 0, 0, 0.28);
  --kg-field-bg-focus: rgba(0, 0, 0, 0.34);
  --kg-field-border: rgba(230, 238, 252, 0.12);
  --kg-field-border-hover: rgba(230, 238, 252, 0.2);
  --kg-field-border-focus: rgba(34, 197, 94, 0.42);
  --kg-field-glow: rgba(34, 197, 94, 0.14);
  --kg-field-surface: rgba(255, 255, 255, 0.028);
  --kg-field-surface-border: rgba(230, 238, 252, 0.09);
  --kg-field-radius: 14px;
  --kg-input-radius: 12px;
  --kg-input-h: 46px;
}

/* ── Bloco de campo (superfície) ─────────────────────────── */
body.kirago-theme .kirago-form .field.kirago-field,
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + input:not([type="checkbox"]):not([type="radio"])),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + textarea),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + select),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + .ui.dropdown),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + .ui.input),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> label + .ui.action.input),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> textarea),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> select),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> .ui.dropdown),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:has(> label + input:not([type="checkbox"])),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:has(> label + .ui.dropdown),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:has(> label + .ui.action.input),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:has(> .ui.toggle.checkbox),
body.kirago-theme .ui.modal > .content .ui.form > .field:has(> .ui.toggle.checkbox),
body.kirago-theme .ui.modal > .content .ui.form .fields > .field:has(input:not([type="checkbox"])),
body.kirago-theme .ui.modal > .content .ui.form .fields > .field:has(.ui.dropdown),
body.kirago-theme .ui.modal > .content .ui.form .fields > .field:has(.ui.input) {
  background: var(--kg-field-surface) !important;
  border: 1px solid var(--kg-field-surface-border) !important;
  border-radius: var(--kg-field-radius) !important;
  padding: 14px 16px 12px !important;
  margin-bottom: 12px !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

body.kirago-theme .kirago-form .field.login-field-token {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin-bottom: 14px !important;
}

body.kirago-theme .kirago-form .field.login-field-token:focus-within {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

body.kirago-theme .kirago-form .field.login-field-token > label {
  margin-bottom: 8px !important;
}

body.kirago-theme .kirago-form .field.kirago-field:not(.login-field-token):hover,
body.kirago-theme .ui.modal > .content .ui.form > .field:has(input, textarea, select, .ui.dropdown, .ui.input):hover,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:hover {
  border-color: var(--kg-field-border-hover) !important;
}

body.kirago-theme .kirago-form .field.kirago-field:not(.login-field-token):focus-within,
body.kirago-theme .ui.modal > .content .ui.form > .field:focus-within:has(input, textarea, select, .ui.dropdown, .ui.input, .ui.action.input),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field:focus-within {
  border-color: var(--kg-field-border-focus) !important;
  box-shadow: 0 0 0 3px var(--kg-field-glow) !important;
  background: rgba(255, 255, 255, 0.038) !important;
}

/* Labels homogêneos */
body.kirago-theme .kirago-form .field > label,
body.kirago-theme .ui.modal > .content .ui.form .field > label,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .field > label {
  display: block !important;
  font-size: 0.72rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.07em !important;
  text-transform: uppercase !important;
  color: rgba(230, 238, 252, 0.62) !important;
  margin: 0 0 10px !important;
  line-height: 1.2 !important;
}

body.kirago-theme .kirago-form .field:focus-within > label,
body.kirago-theme .ui.modal > .content .ui.form .field:focus-within > label,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .field:focus-within > label {
  color: rgba(230, 238, 252, 0.82) !important;
}

/* Inputs, textarea, select */
body.kirago-theme .kirago-form input:not([type="checkbox"]):not([type="radio"]),
body.kirago-theme .kirago-form textarea,
body.kirago-theme .ui.modal > .content .ui.form input:not([type="checkbox"]):not([type="radio"]),
body.kirago-theme .ui.modal > .content .ui.form textarea,
body.kirago-theme .ui.modal > .content .ui.form select,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form input:not([type="checkbox"]):not([type="radio"]),
body.kirago-theme .ui.modal .proxy-modal-body .ui.form textarea {
  min-height: var(--kg-input-h) !important;
  border-radius: var(--kg-input-radius) !important;
  background: var(--kg-field-bg) !important;
  border: 1px solid var(--kg-field-border) !important;
  color: rgba(230, 238, 252, 0.94) !important;
  font-size: 0.94rem !important;
  padding: 0.72em 0.95em !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22) !important;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease !important;
}

body.kirago-theme .kirago-form textarea,
body.kirago-theme .ui.modal > .content .ui.form textarea,
body.kirago-theme #modalInstanceNotesText,
body.kirago-theme .instance-notes-modal-content textarea {
  min-height: 140px !important;
  resize: vertical;
  line-height: 1.45 !important;
  width: 100% !important;
}

body.kirago-theme .instance-notes-modal-content .kirago-form {
  margin: 0;
}

body.kirago-theme .kirago-form input:hover,
body.kirago-theme .kirago-form textarea:hover,
body.kirago-theme .ui.modal > .content .ui.form input:not([type="checkbox"]):hover,
body.kirago-theme .ui.modal > .content .ui.form textarea:hover {
  border-color: var(--kg-field-border-hover) !important;
}

body.kirago-theme .kirago-form input:focus,
body.kirago-theme .kirago-form textarea:focus,
body.kirago-theme .ui.modal > .content .ui.form input:focus,
body.kirago-theme .ui.modal > .content .ui.form textarea:focus,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form input:focus {
  outline: none !important;
  border-color: var(--kg-field-border-focus) !important;
  background: var(--kg-field-bg-focus) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 3px var(--kg-field-glow) !important;
}

body.kirago-theme .kirago-form input::placeholder,
body.kirago-theme .ui.modal > .content .ui.form input::placeholder,
body.kirago-theme .ui.modal > .content .ui.form textarea::placeholder {
  color: rgba(230, 238, 252, 0.38) !important;
}

/* Autofill do navegador — evita fundo branco ao colar/salvar senha */
body.kirago-theme input:-webkit-autofill,
body.kirago-theme input:-webkit-autofill:hover,
body.kirago-theme input:-webkit-autofill:focus,
body.kirago-theme input:-webkit-autofill:active,
body.kirago-theme textarea:-webkit-autofill,
body.kirago-theme textarea:-webkit-autofill:hover,
body.kirago-theme textarea:-webkit-autofill:focus,
body.kirago-theme textarea:-webkit-autofill:active,
body.kirago-theme select:-webkit-autofill {
  -webkit-text-fill-color: rgba(230, 238, 252, 0.94) !important;
  caret-color: rgba(230, 238, 252, 0.94) !important;
  -webkit-box-shadow: 0 0 0 1000px rgba(11, 18, 32, 1) inset !important;
  box-shadow: 0 0 0 1000px rgba(11, 18, 32, 1) inset !important;
  background-color: rgba(11, 18, 32, 1) !important;
  border-color: rgba(230, 238, 252, 0.14) !important;
  transition: background-color 99999s ease, color 99999s ease;
}

body.kirago-theme input:autofill,
body.kirago-theme textarea:autofill,
body.kirago-theme select:autofill {
  -webkit-text-fill-color: rgba(230, 238, 252, 0.94) !important;
  caret-color: rgba(230, 238, 252, 0.94) !important;
  box-shadow: 0 0 0 1000px rgba(11, 18, 32, 1) inset !important;
  border-color: rgba(230, 238, 252, 0.14) !important;
}

body.kirago-theme .login-field-token .login-token-input > input:-webkit-autofill,
body.kirago-theme .login-field-token .login-token-input > input:-webkit-autofill:hover,
body.kirago-theme .login-field-token .login-token-input > input:-webkit-autofill:focus,
body.kirago-theme .login-field-token .login-token-input > input:-webkit-autofill:active,
body.kirago-theme #loginToken:-webkit-autofill,
body.kirago-theme #loginToken:-webkit-autofill:hover,
body.kirago-theme #loginToken:-webkit-autofill:focus,
body.kirago-theme #loginToken:-webkit-autofill:active {
  -webkit-text-fill-color: rgba(230, 238, 252, 0.94) !important;
  caret-color: rgba(230, 238, 252, 0.94) !important;
  border-radius: 12px !important;
  -webkit-box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.45) inset !important;
  box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.45) inset !important;
  background-color: transparent !important;
  border: none !important;
}

/* Dropdown */
body.kirago-theme .ui.modal > .content .ui.form .ui.dropdown,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .ui.dropdown,
body.kirago-theme .kirago-form .ui.dropdown {
  min-height: var(--kg-input-h) !important;
  border-radius: var(--kg-input-radius) !important;
  display: flex !important;
  align-items: center !important;
  padding: 0 0.95em !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22) !important;
}

body.kirago-theme .ui.modal > .content .ui.form .field .ui.dropdown.active,
body.kirago-theme .ui.modal > .content .ui.form .field .ui.dropdown.visible {
  border-color: var(--kg-field-border-focus) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 3px var(--kg-field-glow) !important;
}

/* Action input (token + olho) */
body.kirago-theme .kirago-form .ui.action.input,
body.kirago-theme .ui.modal > .content .ui.form .ui.action.input,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .ui.action.input {
  border-radius: var(--kg-input-radius) !important;
  overflow: hidden !important;
  border: 1px solid var(--kg-field-border) !important;
  background: var(--kg-field-bg) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22) !important;
  display: flex !important;
  width: 100% !important;
}

body.kirago-theme .kirago-form .ui.action.input:focus-within,
body.kirago-theme .ui.modal > .content .ui.form .ui.action.input:focus-within,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .ui.action.input:focus-within {
  border-color: var(--kg-field-border-focus) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 3px var(--kg-field-glow) !important;
}

body.kirago-theme .kirago-form .ui.action.input:not(.login-token-input) > input,
body.kirago-theme .ui.modal > .content .ui.form .ui.action.input > input,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .ui.action.input > input {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  flex: 1 1 auto !important;
  min-height: calc(var(--kg-input-h) - 2px) !important;
  border-radius: 0 !important;
}

body.kirago-theme .kirago-form .ui.action.input.login-token-input {
  overflow: hidden !important;
  border-radius: var(--kg-input-radius) !important;
}

body.kirago-theme .kirago-form .ui.action.input:not(.login-token-input) > .button,
body.kirago-theme .ui.modal > .content .ui.form .ui.action.input > .button,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .ui.action.input > .button {
  border: none !important;
  border-left: 1px solid var(--kg-field-border) !important;
  background: rgba(255, 255, 255, 0.04) !important;
  color: rgba(230, 238, 252, 0.75) !important;
  border-radius: 0 !important;
  margin: 0 !important;
  min-height: var(--kg-input-h) !important;
  width: 48px !important;
}

body.kirago-theme .kirago-form .ui.action.input > .button:hover,
body.kirago-theme .ui.modal > .content .ui.form .ui.action.input > .button:hover {
  background: rgba(255, 255, 255, 0.08) !important;
  color: rgba(230, 238, 252, 0.95) !important;
}

/* Hint / small */
body.kirago-theme .kirago-form .field .ui.description,
body.kirago-theme .kirago-form .field small,
body.kirago-theme .ui.modal > .content .ui.form .field small,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form .field small {
  margin-top: 10px !important;
  font-size: 0.8rem !important;
  line-height: 1.4 !important;
  color: rgba(230, 238, 252, 0.52) !important;
}

/* Toggle dentro do bloco */
body.kirago-theme .ui.modal .ui.form .field .ui.toggle.checkbox label,
body.kirago-theme .kirago-form .ui.toggle.checkbox label {
  font-size: 0.92rem !important;
  font-weight: 600 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  color: rgba(230, 238, 252, 0.9) !important;
}

/* Mensagens dentro do form */
body.kirago-theme .ui.modal > .content .ui.form > .ui.message,
body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .ui.message {
  border-radius: var(--kg-input-radius) !important;
  margin-bottom: 12px !important;
}

body.kirago-theme .ui.modal > .content .ui.form > .ui.divider {
  margin: 1.25rem 0 !important;
  border-top-color: rgba(230, 238, 252, 0.1) !important;
}

/* Grupos lado a lado */
body.kirago-theme .ui.modal > .content .ui.form .fields {
  gap: 10px;
  margin-bottom: 0 !important;
}

body.kirago-theme .ui.modal > .content .ui.form .fields > .field {
  margin-bottom: 12px !important;
}

/* Card login: ver login.css */

/* Segment control (login modo usuário/admin) */
body.kirago-theme .kirago-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(230, 238, 252, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
}

body.kirago-theme .kirago-segment .ui.button {
  border-radius: 999px !important;
  margin: 0 !important;
  min-height: 42px !important;
  font-weight: 700 !important;
  font-size: 0.88rem !important;
  background: transparent !important;
  border: none !important;
  color: rgba(230, 238, 252, 0.55) !important;
  box-shadow: none !important;
}

body.kirago-theme .kirago-segment .ui.button.active {
  background: var(--gradient-primary) !important;
  color: #071016 !important;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.25) !important;
}

body.kirago-theme .kirago-segment .ui.button:not(.active):hover {
  color: rgba(230, 238, 252, 0.88) !important;
  background: rgba(255, 255, 255, 0.05) !important;
}

/* Botão submit login */
body.kirago-theme .kirago-form .ui.primary.fluid.button,
body.kirago-theme .kirago-form #loginSubmitBtn {
  min-height: 48px !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
  letter-spacing: 0.03em !important;
  margin-top: 4px !important;
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.22) !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease !important;
}

body.kirago-theme .kirago-form #loginSubmitBtn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(34, 197, 94, 0.28) !important;
}

/* Modal actions — botões alinhados ao form */
body.kirago-theme .ui.modal > .actions {
  padding: 14px 20px 18px !important;
  gap: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

body.kirago-theme .ui.modal > .actions > .ui.button {
  border-radius: 11px !important;
  min-height: 40px !important;
  font-weight: 600 !important;
  margin: 0 !important;
}

/* Conteúdo modal — respiro */
body.kirago-theme .ui.modal > .content:not(.proxy-modal-content) {
  padding: 1.35rem 1.5rem 1.1rem !important;
}

body.kirago-theme .ui.modal > .content.proxy-modal-content {
  padding: 1.1rem 1.35rem !important;
}

/* ── Mobile: login + modais + campos empilhados ─────────── */
@media (max-width: 768px) {
  body.kirago-theme {
    --kg-input-h: 44px;
    --kg-field-radius: 12px;
  }

  body.kirago-theme .kirago-form .field.kirago-field,
  body.kirago-theme .ui.modal > .content .ui.form > .field,
  body.kirago-theme .ui.modal .proxy-modal-body .ui.form > .field {
    padding: 12px 12px 10px !important;
    margin-bottom: 10px !important;
  }

  body.kirago-theme .kirago-form .field.login-field-token {
    padding: 0 !important;
    margin-bottom: 12px !important;
  }

  body.kirago-theme .kirago-form input:not([type="checkbox"]):not([type="radio"]),
  body.kirago-theme .kirago-form textarea,
  body.kirago-theme .ui.modal > .content .ui.form input:not([type="checkbox"]):not([type="radio"]),
  body.kirago-theme .ui.modal > .content .ui.form textarea {
    font-size: 16px !important; /* evita zoom automático no iOS */
  }

  body.kirago-theme .kirago-segment {
    margin-bottom: 12px;
  }

  body.kirago-theme .kirago-segment .ui.button {
    min-height: 40px !important;
    font-size: 0.8rem !important;
    padding: 0.5rem 0.4rem !important;
  }

  body.kirago-theme .kirago-form .ui.action.input > input,
  body.kirago-theme .ui.modal .ui.action.input > input {
    min-width: 0 !important;
    font-size: 16px !important;
  }

  /* Modais: largura total com margem segura */
  body.kirago-theme .ui.dimmer.modals .ui.modal,
  body.kirago-theme .ui.modal {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    left: 10px !important;
    right: 10px !important;
    margin: 0 auto !important;
    max-height: calc(100dvh - 16px) !important;
    top: 8px !important;
    transform: none !important;
  }

  body.kirago-theme #modalInstanceNotes.ui.modal {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    left: 8px !important;
    right: 8px !important;
    max-height: calc(100dvh - 16px) !important;
  }

  body.kirago-theme .ui.modal > .header.aim-modal-header {
    padding: 16px 14px !important;
    gap: 12px !important;
    flex-wrap: nowrap;
  }

  body.kirago-theme .aim-modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  body.kirago-theme .aim-modal-title {
    font-size: 1.05rem;
  }

  body.kirago-theme .aim-modal-sub {
    font-size: 0.78rem;
  }

  body.kirago-theme .ui.modal > .content:not(.proxy-modal-content),
  body.kirago-theme .ui.modal > .content.proxy-modal-content {
    padding: 0.85rem 0.9rem !important;
  }

  body.kirago-theme .ui.modal > .actions {
    padding: 10px 12px max(12px, env(safe-area-inset-bottom)) !important;
    flex-direction: column-reverse;
    align-items: stretch;
  }

  body.kirago-theme .ui.modal > .actions > .ui.button {
    width: 100% !important;
    margin: 0 !important;
    justify-content: center;
  }

  /* Campos lado a lado → coluna única */
  body.kirago-theme .ui.modal .ui.form .fields,
  body.kirago-theme .ui.modal .ui.form .two.fields,
  body.kirago-theme .ui.modal .ui.form .three.fields,
  body.kirago-theme .ui.modal .ui.form .four.fields {
    flex-direction: column !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  body.kirago-theme .ui.modal .ui.form .fields > .field,
  body.kirago-theme .ui.modal .ui.form .two.fields > .field,
  body.kirago-theme .ui.modal .ui.form .three.fields > .field,
  body.kirago-theme .ui.modal .ui.form .four.fields > .field {
    width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-bottom: 10px !important;
  }

  body.kirago-theme #modalProxyConfig.ui.modal {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 12px) !important;
  }

  body.kirago-theme #modalProxyConfig .proxy-modal-body {
    max-height: min(52dvh, 420px) !important;
  }

  body.kirago-theme #addInstanceModal.ui.modal {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 8px) !important;
  }
}

@media (max-width: 480px) {
  body.kirago-theme .kirago-form .field > label,
  body.kirago-theme .ui.modal .ui.form .field > label {
    font-size: 0.68rem !important;
  }
}
