/**
 * MAK ERP v1.0 — ФАЗА 7 UI Polish (responsive, теми, конзистентност)
 */

:root {
  --mak-ui-radius: 10px;
  --mak-ui-border: #d8dee8;
  --mak-ui-surface: #ffffff;
  --mak-ui-input-bg: #ffffff;
  --mak-ui-input-border: #c5cdd8;
  --mak-ui-shadow: 0 8px 24px rgba(26, 35, 50, 0.06);
  --mak-success-bg: #ecfdf5;
  --mak-success-border: #6ee7b7;
  --mak-success-text: #047857;
  --mak-warn-bg: #fffbeb;
  --mak-warn-border: #fcd34d;
  --mak-warn-text: #b45309;
  --mak-error-bg: #fef2f2;
  --mak-error-border: #fca5a5;
  --mak-error-text: #b91c1c;
  --mak-info-bg: #eff6ff;
  --mak-info-border: #93c5fd;
  --mak-info-text: #1d4ed8;
}

/* ——— Responsive shell ——— */
.content {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

[class*="-table-wrap"],
.table-wrap,
.mak-table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--mak-ui-radius);
}

[class*="-mod-toolbar"],
.vf-mod-toolbar,
.mdoc-toolbar,
.domig-dash-header-actions {
  flex-wrap: wrap;
  gap: 0.5rem;
}

[class*="-mod-form-grid"],
.vf-mod-form-grid,
.mdoc-grid,
.vnes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: 0.75rem 1rem;
}

@media (max-width: 900px) {
  .cfma-menubar { display: none; }
  .cfma-toolbar { flex-wrap: wrap; padding: 0.25rem; }
  .header { flex-wrap: wrap; gap: 0.5rem; }
  .header .status { flex-wrap: wrap; width: 100%; justify-content: flex-start; }
  [class*="-mod-header"],
  .domig-dash-header {
    flex-direction: column;
    align-items: stretch !important;
  }
  .list-pager { flex-wrap: wrap; justify-content: center; }
}

@media (max-width: 600px) {
  .content { padding: 0.75rem !important; }
  button.primary,
  button.secondary,
  button.danger {
    min-height: 40px;
    padding: 0.45rem 0.85rem;
  }
  .modal { max-height: 92vh; margin: 0.5rem; }
}

/* ——— Sticky table headers ——— */
[class*="-table"] thead th,
.data-table thead th,
.mak-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f4f7fb;
  box-shadow: 0 1px 0 #e2e8f0;
}

[class*="-table-wrap"] {
  max-height: min(70vh, 720px);
}

.mdoc-table-wrap,
.pos-cart-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* ——— Unified buttons ——— */
button.primary,
.btn-primary {
  font-weight: 600;
  border-radius: 8px;
}

button.secondary,
.btn-secondary {
  font-weight: 600;
  border-radius: 8px;
}

button.danger {
  border-radius: 8px;
}

/* Toolbar action naming consistency via title attributes in HTML; visual grouping */
[class*="-mod-toolbar"] .primary,
.vf-mod-toolbar .primary,
.mdoc-toolbar .primary {
  min-width: 5.5rem;
}

/* ——— Forms ——— */
label:has(input[required], select[required], textarea[required])::after,
label.field-required::after {
  content: ' *';
  color: var(--danger, #ef4444);
  font-weight: 700;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
  opacity: 1;
}

input[readonly],
select:disabled,
textarea[readonly],
.is-confirmed input:not([type=button]):not([type=submit]),
.is-confirmed select,
.is-confirmed textarea,
tr.is-confirmed input:not([type=button]) {
  background: #f1f5f9 !important;
  color: #475569;
  cursor: default;
}

/* ——— Status badges ——— */
[class*="-badge-ok"],
[class*="-badge-draft"],
.pri-mod-badge-ok,
.vf-mod-badge-ok,
.mdoc-badge-ok {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

[class*="-badge-ok"],
.pri-mod-badge-ok,
.vf-mod-badge-ok,
.mdoc-badge-ok {
  background: var(--mak-success-bg);
  color: var(--mak-success-text);
  border: 1px solid var(--mak-success-border);
}

[class*="-badge-draft"],
[class*="-badge-new"],
.pri-mod-badge-draft,
.vf-mod-badge-draft,
.mdoc-badge-new {
  background: var(--mak-warn-bg);
  color: var(--mak-warn-text);
  border: 1px solid var(--mak-warn-border);
}

/* ——— Messages ——— */
.empty,
[class*="-mod-empty"],
[class*="-empty"],
.domig-dash-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--domig-workspace-muted, #5c6b82);
  font-size: 0.92rem;
  background: #f8fafc;
  border: 1px dashed #dbe3ee;
  border-radius: var(--mak-ui-radius);
}

.loading,
[class*="-mod-loading"],
[class*="-loading"] {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--domig-workspace-muted, #5c6b82);
  font-size: 0.92rem;
}

.loading::after,
[class*="-mod-loading"]::after {
  content: '';
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin-left: 0.5rem;
  border: 2px solid #cbd5e1;
  border-top-color: var(--domig-accent, #1d6fd8);
  border-radius: 50%;
  vertical-align: -0.15em;
  animation: mak-spin 0.7s linear infinite;
}

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

.error-msg {
  padding: 0.85rem 1rem;
  border-radius: var(--mak-ui-radius);
  background: var(--mak-error-bg);
  border: 1px solid var(--mak-error-border);
  color: var(--mak-error-text);
  text-align: left;
}

.error-list {
  margin: 0.5rem 0 0 1.1rem;
  font-size: 0.88rem;
}

.alert-box {
  border-radius: var(--mak-ui-radius);
  padding: 0.75rem 1rem;
  border: 1px solid transparent;
}

.alert-box.ok,
.alert-box.success {
  background: var(--mak-success-bg);
  border-color: var(--mak-success-border);
  color: var(--mak-success-text);
}

.alert-box.warn {
  background: var(--mak-warn-bg);
  border-color: var(--mak-warn-border);
  color: var(--mak-warn-text);
}

.alert-box.info {
  background: var(--mak-info-bg);
  border-color: var(--mak-info-border);
  color: var(--mak-info-text);
}

/* ——— Pagination ——— */
.list-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--mak-ui-surface);
  border: 1px solid var(--mak-ui-border);
  border-radius: var(--mak-ui-radius);
}

.list-pg-info {
  font-size: 0.85rem;
  color: var(--domig-workspace-muted, #5c6b82);
  font-weight: 600;
}

/* ——— Toast ——— */
.mak-toast-stack {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(420px, calc(100vw - 1.5rem));
  pointer-events: none;
}

.mak-toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: var(--mak-ui-radius);
  border: 1px solid transparent;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.mak-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.mak-toast-success { background: var(--mak-success-bg); border-color: var(--mak-success-border); color: var(--mak-success-text); }
.mak-toast-warn { background: var(--mak-warn-bg); border-color: var(--mak-warn-border); color: var(--mak-warn-text); }
.mak-toast-error { background: var(--mak-error-bg); border-color: var(--mak-error-border); color: var(--mak-error-text); }
.mak-toast-info { background: var(--mak-info-bg); border-color: var(--mak-info-border); color: var(--mak-info-text); }

/* ——— Modals & overlays ——— */
.modal-backdrop.open {
  backdrop-filter: blur(4px);
}

.modal,
.mak-login-overlay .modal,
#mak-chgpass-overlay .modal {
  background: var(--mak-ui-surface);
  border: 1px solid var(--mak-ui-border);
  box-shadow: var(--mak-ui-shadow);
}

.modal input,
.modal select,
.modal textarea,
.vnes-form input,
.vnes-form select,
.vnes-form textarea,
[class*="-mod"] input:not([type=checkbox]):not([type=radio]),
[class*="-mod"] select,
[class*="-mod"] textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--mak-ui-input-border);
  border-radius: 8px;
  background: var(--mak-ui-input-bg);
  color: inherit;
  padding: 0.45rem 0.6rem;
  font: inherit;
}

.modal label,
.vnes-form label,
[class*="-mod"] label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--domig-workspace-muted, #5c6b82);
}

/* ——— Dark mode (global) ——— */
body.theme-dark {
  --mak-ui-border: #2a3548;
  --mak-ui-surface: #1a2332;
  --mak-ui-input-bg: #121a28;
  --mak-ui-input-border: #3d4f68;
  --mak-success-bg: rgba(34, 197, 94, 0.12);
  --mak-success-border: rgba(34, 197, 94, 0.35);
  --mak-success-text: #86efac;
  --mak-warn-bg: rgba(245, 158, 11, 0.12);
  --mak-warn-border: rgba(245, 158, 11, 0.35);
  --mak-warn-text: #fcd34d;
  --mak-error-bg: rgba(239, 68, 68, 0.12);
  --mak-error-border: rgba(239, 68, 68, 0.35);
  --mak-error-text: #fca5a5;
  --mak-info-bg: rgba(59, 130, 246, 0.12);
  --mak-info-border: rgba(59, 130, 246, 0.35);
  --mak-info-text: #93c5fd;
}

body.theme-dark .cfma-menubar {
  background: #151d2b;
  border-color: #2a3548;
  color: #e8edf4;
}

body.theme-dark .cfma-menu > button {
  color: #e8edf4;
  border-color: #2a3548;
}

body.theme-dark .cfma-dropdown {
  background: #1a2332;
  border-color: #2a3548;
}

body.theme-dark .cfma-dropdown button {
  color: #e8edf4;
}

body.theme-dark .cfma-dropdown button:hover {
  background: #243044;
}

body.theme-dark [class*="-table"] thead th,
body.theme-dark .data-table thead th {
  background: #243044;
  box-shadow: 0 1px 0 #2a3548;
  color: #e8edf4;
}

body.theme-dark [class*="-table"] td,
body.theme-dark [class*="-table-wrap"],
body.theme-dark .kom-mod-table-wrap,
body.theme-dark .art-mod-table-wrap,
body.theme-dark .pri-mod-table-wrap,
body.theme-dark .vf-mod-table-wrap,
body.theme-dark .if-mod-table-wrap,
body.theme-dark .zal-mod-table-wrap,
body.theme-dark .mdoc-table {
  background: var(--domig-workspace-card);
  border-color: #2a3548;
  color: var(--domig-workspace-text);
}

body.theme-dark .empty,
body.theme-dark [class*="-mod-empty"],
body.theme-dark .loading,
body.theme-dark [class*="-mod-loading"] {
  background: #121a28;
  border-color: #2a3548;
  color: #94a3b8;
}

body.theme-dark .list-pager {
  background: var(--domig-workspace-card);
  border-color: #2a3548;
}

body.theme-dark input[readonly],
body.theme-dark select:disabled,
body.theme-dark textarea[readonly],
body.theme-dark .is-confirmed input:not([type=button]) {
  background: #0f1419 !important;
  color: #94a3b8;
}

body.theme-dark .modal,
body.theme-dark .mak-login-overlay .modal,
body.theme-dark #mak-chgpass-overlay .modal,
body.theme-dark .card,
body.theme-dark .vf-mod-editor-card,
body.theme-dark .mdoc-card {
  background: #1a2332;
  border-color: #2a3548;
  color: #e8edf4;
}

body.theme-dark .mak-login-overlay,
body.theme-dark #mak-chgpass-overlay {
  background: rgba(0, 0, 0, 0.72);
}

body.theme-dark button.secondary {
  background: #243044;
  border-color: #3d4f68;
  color: #e8edf4;
}

body.theme-dark button.primary {
  background: var(--domig-accent, #1d6fd8);
  color: #fff;
}

body.theme-dark .header {
  background: #151d2b;
  border-color: #2a3548;
}

body.theme-dark .mdoc-table-wrap,
body.theme-dark .pos-cart-wrap {
  background: transparent;
}

body.theme-dark .mak-user-badge {
  background: #243044;
  color: #e8edf4;
}

/* POS shell untouched — only global chrome above */
