/* Shared buttons, form fields, modal, flash, and state components.
   Clean & Minimal App UI - Modern Mobile & Desktop App feel
*/

.button {
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-size: var(--font-size-sm);
  font-weight: 750;
  text-align: center;
  cursor: pointer;
  transition: all 140ms ease;
  white-space: nowrap;
}
.button .icon { width: 1.05rem; height: 1.05rem; flex: 0 0 auto; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Primary Filled Button - High Contrast Royal Blue */
.button-primary {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}
.button-primary:hover:not(:disabled) {
  border-color: var(--color-accent-strong);
  background: var(--color-accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.32);
}
.button-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.2);
}

/* Secondary Button - Crisp White with Subtle Border */
.button-secondary {
  border-color: var(--color-border);
  background: #ffffff;
  color: var(--color-text-soft);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.button-secondary:hover:not(:disabled) {
  background: var(--color-page);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--color-text-soft);
}
.button-quiet:hover:not(:disabled) {
  border-color: var(--color-border);
  background: var(--color-surface-soft);
  color: var(--color-accent);
}

.button-danger-soft {
  border-color: #fecdd3;
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.button-danger-soft:hover:not(:disabled) {
  background: #fee2e2;
  border-color: #fca5a5;
}

.button-success-soft {
  border-color: #bbf7d0;
  background: var(--color-success-soft);
  color: var(--color-success);
}
.button-success-soft:hover:not(:disabled) {
  background: #dcfce7;
  border-color: #86efac;
}

.button-small {
  min-height: 2.1rem;
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 750;
  white-space: nowrap;
}
.button-block { width: 100%; }

.icon-button {
  display: inline-grid;
  width: 2.45rem;
  height: 2.45rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--color-text-soft);
  cursor: pointer;
  transition: all 130ms ease;
}
.icon-button:hover {
  border-color: var(--color-border);
  background: var(--color-surface-soft);
  color: var(--color-accent);
}

.sort-cycle {
  min-height: 2.45rem;
  padding-inline: 0.75rem;
  font-size: var(--font-size-xs);
  white-space: nowrap;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: #ffffff;
}

/* Forms & Clean Input Fields */
.stacked-form { display: flex; flex-direction: column; gap: 1rem; }
.form-field { display: flex; min-width: 0; flex-direction: column; gap: 0.4rem; }
.form-field > label, .field-label { color: var(--color-text); font-size: var(--font-size-sm); font-weight: 750; }

.form-control, .select-trigger, .select-search input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--control-height);
  padding: 0.58rem 0.85rem;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  outline: 0;
  background: #ffffff;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  transition: border-color 130ms ease, box-shadow 130ms ease, background 130ms ease;
}
.form-control::placeholder, .select-search input::placeholder { color: #94a3b8; }
.form-control:hover, .select-trigger:hover, .select-search input:hover { border-color: var(--color-border-strong); }
.form-control:focus, .select-trigger:focus-visible, .select-search input:focus {
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
  background: #ffffff;
}
textarea.form-control { min-height: 6.5rem; resize: vertical; }

.form-row { display: flex; align-items: center; gap: 0.75rem; }
.form-row-between { justify-content: space-between; }
.checkbox-field { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--color-text-soft); font-size: var(--font-size-xs); cursor: pointer; }
.checkbox-field input { width: 1.05rem; height: 1.05rem; accent-color: var(--color-accent); border-radius: 4px; }
.field-hint { margin: 0; line-height: 1.5; color: var(--color-text-muted); font-size: var(--font-size-xs); }
.field-errors { display: flex; flex-direction: column; gap: 0.15rem; margin: 0; padding-inline-start: 1.2rem; color: var(--color-danger); font-size: var(--font-size-xs); }
.field-error-message { margin: 0.5rem 0 0; color: var(--color-danger); font-size: var(--font-size-xs); }
.form-actions { display: flex; justify-content: flex-start; gap: 0.6rem; margin-top: 0.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-note {
  display: flex;
  align-items: start;
  gap: 0.6rem;
  margin-top: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--color-text-soft);
  font-size: var(--font-size-xs);
}
.form-note .icon { width: 1.05rem; height: 1.05rem; color: var(--color-accent); flex: 0 0 auto; }

/* Searchable select */
.searchable-select { position: relative; }
.select-trigger { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; text-align: right; cursor: pointer; }
.select-trigger [data-select-label] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-trigger.is-placeholder [data-select-label] { color: #94a3b8; }
.select-chevron { width: 1rem; height: 1rem; color: var(--color-text-muted); }
.select-popover {
  position: absolute;
  z-index: 80;
  top: calc(100% + 0.35rem);
  right: 0;
  left: 0;
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}
.select-popover[hidden] { display: none; }
.select-search { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem; border-bottom: 1px solid var(--color-border); }
.select-search > .icon { color: var(--color-text-muted); width: 1rem; height: 1rem; }
.select-search input { min-height: 2.25rem; padding: 0.4rem 0.6rem; border-color: transparent; border-radius: 8px; }
.select-search input:focus { box-shadow: none; border-color: var(--color-accent); }
.select-options { max-height: 14rem; overflow-y: auto; margin: 0; padding: 0.35rem; list-style: none; }
.select-option {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.6rem 0.7rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text);
  text-align: right;
  cursor: pointer;
  transition: background 120ms ease;
}
.select-option:hover, .select-option:focus-visible { background: var(--color-surface-soft); }
.select-option[aria-selected="true"] { background: var(--color-surface-soft); color: var(--color-accent); font-weight: 800; }
.select-option small { color: var(--color-text-muted); font-size: 0.7rem; font-weight: 400; }
.select-empty { margin: 0; padding: 0.8rem; color: var(--color-text-muted); font-size: var(--font-size-xs); text-align: center; }
.select-empty[hidden] { display: none; }
.field-hint[data-select-error] { color: var(--color-danger); }
.searchable-select.has-error .select-trigger { border-color: var(--color-danger); }

/* Clean Modern App Dialogs */
.modal-dialog {
  width: min(100% - 2rem, 42rem);
  max-width: 42rem;
  max-height: min(90vh, 52rem);
  padding: 0;
  overflow: visible;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  background: #ffffff;
  color: var(--color-text);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}
.modal-dialog::backdrop { background: rgb(15 23 42 / 46%); backdrop-filter: blur(4px); }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.4rem;
  border-bottom: 1px solid #f1f5f9;
  background: #ffffff;
  border-radius: 18px 18px 0 0;
}
.modal-header h2 { margin: 0.15rem 0 0; font-size: 1.25rem; font-weight: 850; color: #0f172a; }
.modal-header p { margin: 0.2rem 0 0; color: var(--color-text-muted); font-size: var(--font-size-xs); }
.modal-body { max-height: calc(90vh - 11rem); overflow-y: auto; padding: 1.25rem 1.4rem; }
.modal-footer {
  display: flex;
  justify-content: flex-start;
  gap: 0.65rem;
  padding: 0.95rem 1.4rem;
  border-top: 1px solid #f1f5f9;
  background: #f8fafc;
  border-radius: 0 0 18px 18px;
}
.modal-form { overflow: hidden; border-radius: inherit; }
.modal-form .form-grid { align-items: start; }
.modal-dialog[open] { animation: modal-in 140ms ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(0.5rem) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Toast Notifications */
.flash-stack { position: fixed; z-index: 120; top: 1.1rem; left: 1.1rem; display: flex; width: min(25rem, calc(100vw - 2.2rem)); flex-direction: column; gap: 0.6rem; }
.flash { display: flex; align-items: start; gap: 0.65rem; padding: 0.85rem; border: 1px solid var(--color-border); border-radius: 12px; background: #ffffff; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); }
.flash p { flex: 1; margin: 0; font-size: var(--font-size-xs); font-weight: 650; }
.flash-indicator { width: 0.45rem; height: 0.45rem; flex: 0 0 auto; margin-top: 0.43rem; border-radius: 50%; background: var(--color-info); }
.flash-success { border-color: #bbf7d0; background: #f0fdf4; }
.flash-success .flash-indicator { background: var(--color-success); }
.flash-warning { border-color: #fde68a; background: #fffbeb; }
.flash-warning .flash-indicator { background: var(--color-warning); }
.flash-error { border-color: #fecdd3; background: #fef2f2; }
.flash-error .flash-indicator { background: var(--color-danger); }
.flash-close { width: 1.8rem; height: 1.8rem; border-radius: 6px; }
.flash-close .icon { width: 0.9rem; height: 0.9rem; }
.flash.is-hiding { opacity: 0; transform: translateY(-0.3rem); transition: opacity 150ms ease, transform 150ms ease; }

/* Error pages */
.error-page { display: grid; min-height: 65vh; place-items: center; padding: 2rem; }
.error-panel { width: min(100%, 32rem); padding: 2.2rem; border: 1px solid var(--color-border); border-radius: 18px; text-align: center; background: #ffffff; box-shadow: var(--shadow-card); }
.error-code { color: var(--color-accent); font-size: 3.5rem; font-weight: 900; line-height: 1.15; }
.error-panel h1 { margin: 0.6rem 0; font-size: var(--font-size-xl); }
.error-panel p { margin: 0 0 1.25rem; color: var(--color-text-soft); font-size: var(--font-size-sm); }

/* Remote searchable reference fields */
.remote-select { position: relative; min-width: 0; }
.remote-select-input { padding-inline-end: 0.85rem; }
.remote-select-popover {
  position: absolute;
  z-index: 90;
  inset-inline: 0;
  top: calc(100% + 0.35rem);
  max-height: 17rem;
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
}
.remote-select-popover[hidden], .remote-select-status[hidden] { display: none !important; }
.remote-select-status { margin: 0; padding: 0.85rem; color: var(--color-text-muted); font-size: var(--font-size-xs); text-align: center; }
.remote-select-options { max-height: 14.5rem; overflow-y: auto; padding: 0.35rem; }
.remote-select-option {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.65rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text);
  text-align: right;
  cursor: pointer;
  transition: background 120ms ease;
}
.remote-select-option:hover, .remote-select-option:focus-visible { background: var(--color-surface-soft); }
.remote-option-label { font-size: var(--font-size-sm); font-weight: 750; color: #0f172a; }
.remote-option-meta { color: var(--color-text-muted); font-size: 0.7rem; }
.remote-select-meta { margin: 0; color: var(--color-accent-strong); font-size: 0.72rem; }
.remote-select-meta[hidden] { display: none !important; }
.remote-select.has-error .remote-select-input { border-color: var(--color-danger); }
.remote-select [data-remote-error][hidden] { display: none; }
.form-note-warning { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.form-note-warning .icon { color: #d97706; }
.inline-error { margin: 0.5rem 0; color: var(--color-danger); font-size: var(--font-size-xs); }
.inline-error[hidden] { display: none !important; }

/* Notification bell */
.notification-bell {
  position: relative;
  display: inline-grid;
  width: 2.45rem;
  height: 2.45rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--color-text-soft);
  transition: all 130ms ease;
}
.notification-bell:hover { border-color: var(--color-border-strong); background: var(--color-surface-soft); color: var(--color-accent); }
.notification-badge {
  position: absolute;
  top: -0.3rem;
  inset-inline-start: -0.35rem;
  display: inline-flex;
  min-width: 1.15rem;
  height: 1.15rem;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: var(--color-danger);
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 900;
  line-height: 1;
}

@media (max-width: 640px) {
  .button { min-height: 2.55rem; padding: 0.45rem 0.85rem; }
  .form-grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .modal-dialog { width: calc(100% - 1rem); max-height: calc(100dvh - 1rem); margin: auto; border-radius: 14px; }
  .modal-header { padding: 1rem 1.15rem; border-radius: 14px 14px 0 0; }
  .modal-body { max-height: calc(100dvh - 9.5rem); padding: 1rem 1.15rem; }
  .modal-footer { padding: 0.8rem 1.15rem; border-radius: 0 0 14px 14px; }
  .modal-footer .button { flex: 1; }
  .flash-stack { top: 0.6rem; left: 0.6rem; width: calc(100vw - 1.2rem); }
}
