/* ==========================================================================
   MOBILE CORE V3 — ZERO-FRICTION UNIVERSAL SHELL ADAPTER (CSS)
   Hedef: /demo/ Ana Katalog (Sınıf 0) + 115 Sektörel ERP/CRM/POS Demosu (Sınıf A, B, C)
   Sözleşme:
   - Yalnızca --mc-* değişken uzayı ve mc-* sınıf öneki kullanılır.
   - Masaüstü (> 768px) görünümüne hiçbir müdahale yapılmaz.
   - >= 48x48 CSS px dokunma hedefi | >= 16px form/tablo girdi metni | 0px yatay taşma
   ========================================================================== */

:root {
  --mc-bg: #F4F7FB;
  --mc-surface: #FFFFFF;
  --mc-surface-2: #EBF1F7;
  --mc-surface-glass: rgba(255, 255, 255, 0.92);
  --mc-ink: #0F172A;
  --mc-ink-2: #334155;
  --mc-muted: #526277;
  --mc-line: #D8E2EE;
  --mc-line-strong: #BCCBE0;
  --mc-brand: #1554D1;
  --mc-brand-strong: #0F3FA6;
  --mc-brand-tint: #EAF1FF;
  --mc-on-brand: #FFFFFF;
  --mc-success: #067647;
  --mc-success-tint: #E6F6EE;
  --mc-warning: #B54708;
  --mc-warning-tint: #FEF4E6;
  --mc-danger: #B42318;
  --mc-danger-tint: #FEECEB;
  --mc-focus-ring: #1554D1;
  --mc-scrim: rgba(15, 23, 42, 0.56);
  --mc-toast-bg: #0F172A;
  --mc-toast-ink: #F8FAFC;
  --mc-toast-link: #93C5FD;
  --mc-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --mc-shadow-xl: 0 24px 64px rgba(15, 23, 42, 0.22);
  --mc-r-sm: 12px;
  --mc-r-md: 16px;
  --mc-r-lg: 22px;
  --mc-topbar-h: 60px;
  --mc-bottom-h: 68px;
  --mc-sat: env(safe-area-inset-top, 0px);
  --mc-sab: env(safe-area-inset-bottom, 0px);
  --mc-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mc-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

html[data-mc-theme="dark"] {
  --mc-bg: #0B111E;
  --mc-surface: #131D31;
  --mc-surface-2: #1D2B44;
  --mc-surface-glass: rgba(19, 29, 49, 0.92);
  --mc-ink: #F1F5F9;
  --mc-ink-2: #CBD5E1;
  --mc-muted: #94A3B8;
  --mc-line: #263652;
  --mc-line-strong: #394E73;
  --mc-brand: #76A9FA;
  --mc-brand-strong: #A4CAFE;
  --mc-brand-tint: rgba(118, 169, 250, 0.16);
  --mc-on-brand: #091326;
  --mc-success: #4ADE80;
  --mc-success-tint: rgba(74, 222, 128, 0.15);
  --mc-warning: #FBBF24;
  --mc-warning-tint: rgba(251, 191, 36, 0.15);
  --mc-danger: #FCA5A5;
  --mc-danger-tint: rgba(252, 165, 165, 0.16);
  --mc-focus-ring: #76A9FA;
  --mc-scrim: rgba(2, 6, 23, 0.74);
  --mc-toast-bg: #F1F5F9;
  --mc-toast-ink: #0F172A;
  --mc-toast-link: #1554D1;
  --mc-shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.35);
  --mc-shadow-xl: 0 26px 70px rgba(0, 0, 0, 0.58);
}

/* Masaüstü (> 768px) Koruma Kalkanı: Kabuk öğeleri tamamen gizlenir */
@media (min-width: 769px) {
  .mc-shell-svg,
  .mc-topbar,
  .mc-bottom-nav,
  .mc-sheet-layer,
  .mc-toast-bar {
    display: none !important;
  }
}

/* ==========================================================================
   MOBİL KABUK KURALLARI (Yalnızca <= 768px altında devreye girer)
   ========================================================================== */
@media (max-width: 768px) {
  html,
  body {
    max-width: 100% !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  body {
    padding-top: calc(var(--mc-topbar-h) + var(--mc-sat)) !important;
    padding-bottom: calc(var(--mc-bottom-h) + var(--mc-sab) + 12px) !important;
  }

  /* Koyu Tema (Mobil Kabuk Aktifken) */
  html[data-mc-theme="dark"] body,
  html[data-mc-theme="dark"] .erp-app,
  html[data-mc-theme="dark"] .center-stage,
  html[data-mc-theme="dark"] .kp-main,
  html[data-mc-theme="dark"] .app-main {
    background-color: var(--mc-bg) !important;
    color: var(--mc-ink) !important;
  }

  /* Klavye Odak Halkası */
  .mc-topbar :focus-visible,
  .mc-bottom-nav :focus-visible,
  .mc-sheet-layer :focus-visible {
    outline: 3px solid var(--mc-focus-ring) !important;
    outline-offset: 2px !important;
    border-radius: 8px;
  }

  /* SVG İkon Yardımcıları */
  .mc-shell-svg {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
  }
  svg.mc-ico {
    display: block;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.95;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* ---------------- 1. MOBİL ÜST ÇUBUK (TOPBAR: 60px + safe-area) ---------------- */
  .mc-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--mc-topbar-h) + var(--mc-sat));
    padding: var(--mc-sat) 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    background: var(--mc-surface-glass);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--mc-line);
    color: var(--mc-ink);
    font-family: var(--mc-font);
    z-index: 9990;
    box-shadow: var(--mc-shadow-xs);
  }

  .mc-topbar-start {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    flex: 1;
  }

  .mc-brand-home-btn {
    min-height: 48px;
    padding: 4px 8px;
    border-radius: 12px;
    border: 0;
    background: transparent;
    color: var(--mc-ink);
    display: inline-flex;
    align-items: center;
    gap: 9px;
    text-align: left;
    min-width: 0;
    cursor: pointer;
    touch-action: manipulation;
  }
  .mc-brand-home-btn:active {
    background: var(--mc-surface-2);
  }
  .mc-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: var(--mc-brand);
    color: var(--mc-on-brand);
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }
  .mc-brand-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
  }
  .mc-brand-title {
    font-size: 0.90625rem;
    font-weight: 850;
    letter-spacing: -0.02em;
    color: var(--mc-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
  }
  .mc-brand-sub {
    font-size: 0.6875rem;
    font-weight: 650;
    color: var(--mc-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
  }

  .mc-context-title {
    font-size: 0.9375rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--mc-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 4px;
  }

  .mc-topbar-end {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
  }

  /* Zorunlu 48x48 CSS px İkon Butonu */
  .mc-icon-btn {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    border-radius: 14px;
    border: 0;
    background: transparent;
    color: var(--mc-ink);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.14s, transform 0.12s;
  }
  .mc-icon-btn:hover,
  .mc-icon-btn:active {
    background: var(--mc-surface-2);
  }
  .mc-icon-btn[hidden],
  .mc-brand-home-btn[hidden],
  .mc-context-title[hidden],
  .mc-sheet-layer[hidden],
  .mc-toast-bar[hidden] {
    display: none !important;
  }

  /* ---------------- 2. TİCARİ DEMO ÜST ŞERİDİ (.hh-demo-seo-bar) KOMPAKT UYUMU ---------------- */
  .hh-demo-seo-bar {
    padding: 4px 10px !important;
    font-size: 11.5px !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  .hh-demo-seo-bar > div:first-child {
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
  .hh-demo-seo-bar h1 {
    font-size: 11.5px !important;
    max-width: 34vw !important;
  }
  .hh-demo-seo-bar a {
    min-height: 34px !important;
    display: inline-flex !important;
    align-items: center !important;
    white-space: nowrap !important;
  }
  .hh-demo-seo-bar details:not([open]) summary {
    font-size: 10.5px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* ---------------- 3. SINIF 0 (/demo/ Katalog) & SINIF A/B/C MİMARİ UYUMU ---------------- */
  /* Sınıf 0 (/demo/) mevcut üst header'ı mobilde kabuk üst çubuğuyla çakışmasın */
  body.mc-class-0 > header.header {
    display: none !important;
  }
  body.mc-class-0 .quick-search-pills {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 6px !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch;
  }
  body.mc-class-0 .quick-search-pills::-webkit-scrollbar {
    display: none !important;
  }
  body.mc-class-0 .quick-search-chip,
  body.mc-class-0 .type-tab,
  body.mc-class-0 .sector-pill {
    min-height: 48px !important;
    display: inline-flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
  }

  /* Sınıf B (MDI 100vh/100vw Uygulamaları) Mobil Yükseklik ve Taşma Koruması */
  .erp-app {
    width: 100% !important;
    max-width: 100% !important;
    height: calc(100dvh - var(--mc-topbar-h) - var(--mc-sat) - var(--mc-bottom-h) - var(--mc-sab) - 42px) !important;
    min-height: 420px !important;
  }
  /* MDI masaüstü üst çubuğu DOM'da kalır (sekme tıklama köprüsü için) ancak mobilde yer kaplamaz */
  .erp-app > .top-bar {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
  .erp-body,
  .center-stage,
  #centerStage,
  .kp-main,
  .app-main {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  .center-stage,
  #centerStage {
    padding: 12px 12px calc(var(--mc-bottom-h) + var(--mc-sab) + 28px) !important;
  }

  /* Sınıf C (#kpSidebar sabit sol ray) mobilde içeriği sağa itmesin */
  .kp-main {
    margin-left: 0 !important;
    padding-left: 0 !important;
  }
  #kpSidebar:not(.mc-force-open) {
    transform: translateX(-105%) !important;
  }

  /* Sınıf A (Yan menülü ERP'ler) mobilde kapalı başlasın, içerik tam genişlik alsın */
  .erp-sidebar:not(.open):not(.mc-force-open),
  aside.sidebar:not(.open):not(.mc-force-open),
  aside.side:not(.open):not(.mc-force-open) {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    transform: translateX(-105%) !important;
    z-index: 9980 !important;
  }
  .erp-main,
  #mainWorkspace {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ---------------- 4. BAĞLAMSAL ALT GEZİNME ÇUBUĞU (64px + safe-area) ---------------- */
  .mc-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: calc(var(--mc-bottom-h) + var(--mc-sab));
    padding: 6px 10px calc(6px + var(--mc-sab));
    background: var(--mc-surface-glass);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    border-top: 1px solid var(--mc-line);
    font-family: var(--mc-font);
    z-index: 9990;
    transition: transform 0.2s var(--mc-ease), opacity 0.2s;
  }

  /* Sanal klavye açıldığında alt gezinme çubuğu gizlenir */
  html.mc-keyboard-open .mc-bottom-nav {
    transform: translateY(110%) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .mc-web-cta-bar {
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 8px;
    align-items: center;
  }

  .mc-app-tab-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    align-items: center;
  }

  .mc-tab-item {
    min-height: 54px !important;
    min-width: 48px !important;
    padding: 4px 2px;
    border-radius: 12px;
    border: 0;
    background: transparent;
    color: var(--mc-muted);
    font-family: var(--mc-font);
    font-size: 0.70rem;
    font-weight: 750;
    line-height: 1.15;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    position: relative;
    cursor: pointer;
    touch-action: manipulation;
    text-align: center;
  }
  .mc-tab-item span.mc-tab-lbl {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 2px;
  }
  .mc-tab-item[aria-current="page"] {
    background: var(--mc-brand-tint);
    color: var(--mc-brand);
    font-weight: 850;
  }
  .mc-tab-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 24px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--mc-brand);
    color: var(--mc-on-brand);
    font-size: 0.625rem;
    font-weight: 850;
    display: grid;
    place-items: center;
  }

  /* Kabuk Butonları (>= 50px) */
  .mc-btn {
    min-height: 50px !important;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-family: var(--mc-font);
    font-size: 0.875rem;
    font-weight: 780;
    line-height: 1.2;
    text-align: center;
    text-decoration: none !important;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.12s;
  }
  .mc-btn:active {
    transform: scale(0.985);
  }
  .mc-btn-primary {
    background: var(--mc-brand) !important;
    color: var(--mc-on-brand) !important;
  }
  .mc-btn-secondary {
    background: var(--mc-surface) !important;
    border-color: var(--mc-line-strong) !important;
    color: var(--mc-ink) !important;
  }
  .mc-btn-soft {
    background: var(--mc-brand-tint) !important;
    color: var(--mc-brand) !important;
  }
  .mc-btn-block {
    width: 100%;
  }

  /* ---------------- 5. SÜRÜKLENEBİLİR ALT PANEL (BOTTOM SHEET) ---------------- */
  .mc-sheet-layer {
    position: fixed;
    inset: 0;
    background: var(--mc-scrim);
    z-index: 9998;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-family: var(--mc-font);
    color: var(--mc-ink);
  }
  .mc-sheet-box {
    width: 100%;
    max-height: 86dvh;
    background: var(--mc-surface);
    border-radius: 24px 24px 0 0;
    box-shadow: var(--mc-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: mcSheetRise 0.22s var(--mc-ease);
  }
  @keyframes mcSheetRise {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .mc-sheet-handle {
    padding: 10px 0 4px;
    display: grid;
    place-items: center;
    cursor: grab;
    touch-action: none;
  }
  .mc-sheet-handle i {
    display: block;
    width: 42px;
    height: 5px;
    border-radius: 99px;
    background: var(--mc-line-strong);
  }
  .mc-sheet-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 12px 10px 18px;
    border-bottom: 1px solid var(--mc-line);
  }
  .mc-sheet-title {
    font-size: 1.05rem;
    font-weight: 820;
    letter-spacing: -0.02em;
    color: var(--mc-ink);
    margin: 0;
  }
  .mc-sheet-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px calc(24px + var(--mc-sab));
  }

  .mc-stack {
    display: grid;
    gap: 9px;
  }
  .mc-section-lbl {
    font-size: 0.72rem;
    font-weight: 820;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mc-muted);
    margin: 10px 2px 4px;
  }
  .mc-nav-card {
    width: 100%;
    min-height: 58px !important;
    padding: 11px 13px;
    border-radius: var(--mc-r-md);
    background: var(--mc-surface);
    border: 1px solid var(--mc-line);
    color: var(--mc-ink);
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    text-decoration: none !important;
    box-shadow: var(--mc-shadow-xs);
    cursor: pointer;
    touch-action: manipulation;
  }
  .mc-nav-card.mc-active {
    border-color: var(--mc-brand);
    background: var(--mc-brand-tint);
  }
  .mc-card-ico {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--mc-brand-tint);
    color: var(--mc-brand);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-weight: 800;
    font-size: 0.85rem;
  }
  .mc-card-copy {
    flex: 1;
    min-width: 0;
  }
  .mc-card-copy strong {
    display: block;
    font-size: 0.90625rem;
    font-weight: 770;
    color: var(--mc-ink);
    line-height: 1.28;
  }
  .mc-card-copy small {
    display: block;
    margin-top: 2px;
    font-size: 0.78rem;
    color: var(--mc-muted);
    line-height: 1.35;
  }

  .mc-search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 0 14px;
    border-radius: 14px;
    background: var(--mc-surface);
    border: 1px solid var(--mc-line-strong);
    box-shadow: var(--mc-shadow-xs);
  }
  .mc-search-box input {
    flex: 1;
    min-width: 0;
    min-height: 48px;
    border: 0 !important;
    background: transparent !important;
    color: var(--mc-ink) !important;
    font-size: 16px !important;
    outline: none !important;
  }

  /* ---------------- 6. DOKUNMA ALANI (>= 48px) VE FORM (16px) STANDARDI ---------------- */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select,
  textarea {
    font-size: 16px !important;
    min-height: 44px;
  }

  /* Grafik ve Görsel Taşma Koruması */
  canvas,
  svg:not(.mc-ico) {
    max-width: 100% !important;
  }

  /* ---------------- 7. YIKICI OLMAYAN TABLO KART DÖNÜŞÜMÜ & MATRİS İSTİSNASI ---------------- */
  /* Çok sütunlu matrisler (13 hafta nakit, Gantt, projeksiyon) yatay kaydırma kapsayıcısında korunur */
  .mc-scroll-x,
  .table-scroll,
  .table-wrap,
  .kp-table-wrap {
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Standart Veri ve Canlı Hesaplama Tabloları -> Mobil Kart Görünümü (DOM ve input'lar korunur) */
  table.mc-card-table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border: 0 !important;
  }
  table.mc-card-table thead {
    display: none !important;
  }
  table.mc-card-table tbody {
    display: block !important;
    width: 100% !important;
  }
  table.mc-card-table tbody tr {
    display: block !important;
    width: 100% !important;
    background: var(--mc-surface) !important;
    border: 1px solid var(--mc-line) !important;
    border-radius: 14px !important;
    padding: 10px 12px !important;
    margin-bottom: 10px !important;
    box-shadow: var(--mc-shadow-xs) !important;
  }
  table.mc-card-table tbody td {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    width: 100% !important;
    min-height: 40px !important;
    padding: 6px 2px !important;
    border: 0 !important;
    border-bottom: 1px dashed var(--mc-line) !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
  }
  table.mc-card-table tbody td:last-child {
    border-bottom: 0 !important;
  }
  table.mc-card-table tbody td[data-mc-label]::before {
    content: attr(data-mc-label);
    font-size: 0.76rem;
    font-weight: 760;
    color: var(--mc-muted);
    text-align: left;
    flex-shrink: 0;
    max-width: 46%;
  }
  table.mc-card-table tbody td[colspan] {
    justify-content: center !important;
    text-align: center !important;
  }
  table.mc-card-table tbody td[colspan]::before {
    display: none !important;
  }
  table.mc-card-table tbody td input:not([type="checkbox"]):not([type="radio"]),
  table.mc-card-table tbody td select {
    min-height: 44px !important;
    font-size: 16px !important;
    max-width: 58% !important;
  }
  table.mc-card-table tbody td button {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Bildirim Çubuğu (Toast) */
  .mc-toast-bar {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: calc(var(--mc-bottom-h) + var(--mc-sab) + 12px);
    z-index: 9999;
    background: var(--mc-toast-bg);
    color: var(--mc-toast-ink);
    border-radius: 14px;
    padding: 10px 14px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-family: var(--mc-font);
    font-size: 0.84375rem;
    font-weight: 680;
    box-shadow: var(--mc-shadow-xl);
  }

  /* 320px Kompakt Ekran Güvencesi */
  @media (max-width: 359px) {
    .mc-web-cta-bar {
      grid-template-columns: 1fr 1.15fr;
      gap: 6px;
    }
    .mc-btn {
      padding: 8px 10px;
      font-size: 0.8125rem;
    }
  }
}
