/**
 * Markino Portfolio Manager - Responsive Layout Styles
 * Breakpoints: Mobile (320-767px), Tablet (768-1024px), Laptop (1280px), Desktop (1440px+)
 */

/* ==========================================================================
   Base Mobile Safety & Prevention of Horizontal Scrolling
   ========================================================================== */
html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  -webkit-tap-highlight-color: transparent;
}

.mk-shell {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Close button in mobile drawer - hidden on desktop */
.mk-mobile-close-btn {
  display: none;
}

/* ==========================================================================
   Tablet & Medium Screens (max-width: 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  :root {
    --mk-sidebar-w: 0px;
  }

  .mk-sidebar {
    transform: translateX(-100%);
    width: 280px;
    max-width: 85vw;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    box-shadow: 10px 0 35px rgba(0, 0, 0, 0.85);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .mk-sidebar.open {
    transform: translateX(0);
  }

  .mk-mobile-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--mk-radius-sm);
    background: var(--mk-surface-2);
    border: 1px solid var(--mk-border);
    color: var(--mk-text-muted);
    cursor: pointer;
    margin-left: auto;
    font-size: 15px;
    transition: var(--mk-transition);
  }

  .mk-mobile-close-btn:hover {
    color: #FFFFFF;
    border-color: var(--mk-primary);
  }

  .mk-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden;
  }

  .mk-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--mk-radius-sm);
    background: var(--mk-surface);
    border: 1px solid var(--mk-border);
    color: var(--mk-text);
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--mk-transition);
  }

  .mk-mobile-toggle:hover {
    border-color: var(--mk-primary);
    color: var(--mk-primary);
  }

  .mk-portfolio-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
  }

  .mk-page-body {
    padding: 20px 16px;
    width: 100%;
    box-sizing: border-box;
  }

  .mk-header {
    padding: 0 16px;
  }

  /* Overlay backdrop for mobile drawer */
  .mk-sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .mk-sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }
}

/* ==========================================================================
   Mobile Smartphones (max-width: 767px)
   ========================================================================== */
@media (max-width: 767px) {
  /* Prevent iOS Safari input auto-zoom */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Header & Navigation */
  .mk-header {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
    justify-content: space-between;
  }

  .mk-header-left {
    gap: 8px;
    max-width: none;
    flex: 1;
    min-width: 0;
  }

  .mk-mobile-toggle {
    width: 38px;
    height: 38px;
  }

  .mk-search-trigger {
    padding: 6px 10px;
    height: 38px;
    min-width: 0;
    flex: 1;
  }

  .mk-search-trigger span.placeholder-text {
    display: none;
  }

  .mk-search-trigger::after {
    content: "Search...";
    color: var(--mk-text-muted);
    font-size: 13px;
  }

  .mk-kbd-badge {
    display: none !important;
  }

  .mk-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .mk-header-hide-mobile {
    display: none !important;
  }

  .mk-header-add-btn {
    padding: 0 12px;
    height: 38px;
    font-size: 13px;
    gap: 4px;
    display: inline-flex;
    align-items: center;
  }

  /* Page Body & Header */
  .mk-page-body {
    padding: 16px 12px 32px;
  }

  .mk-page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }

  .mk-page-header > div:first-child {
    width: 100%;
  }

  .mk-page-header > div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .mk-page-header .mk-btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
    height: 42px;
  }

  .mk-page-title {
    font-size: 20px;
  }

  .mk-page-subtitle {
    font-size: 12.5px;
  }

  /* Statistics Dashboard */
  .mk-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
  }

  .mk-stat-card {
    padding: 14px 12px;
    border-radius: 10px;
  }

  .mk-stat-header {
    font-size: 11px;
  }

  .mk-stat-value {
    font-size: 20px;
  }

  .mk-stat-sub {
    font-size: 10.5px;
  }

  /* Controls & Filters Bar */
  .mk-controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 18px;
  }

  .mk-select-all-wrap {
    width: 100%;
    height: 42px;
    justify-content: flex-start;
    padding: 0 12px;
    box-sizing: border-box;
  }

  .mk-filter-input,
  .mk-filter-select {
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 12px;
    box-sizing: border-box;
  }

  #mk-copy-links-btn {
    width: 100%;
    height: 44px;
    justify-content: center;
    font-size: 13.5px;
    font-weight: 600;
    margin-top: 2px;
  }

  #mk-results-count {
    width: 100%;
    text-align: center;
    margin: 4px 0 0;
    font-size: 11.5px;
  }

  /* Portfolio Grid & Cards */
  .mk-portfolio-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .mk-card {
    border-radius: 12px;
  }

  .mk-card-media {
    height: 195px;
  }

  .mk-card-badges {
    top: 8px;
    left: 8px;
    gap: 4px;
  }

  .mk-badge {
    font-size: 10px;
    padding: 3px 6px;
  }

  .mk-card-niche-select {
    max-width: 115px;
    font-size: 10px;
    padding: 2px 16px 2px 6px;
  }

  .mk-fav-btn {
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
  }

  .mk-card-body {
    padding: 14px;
  }

  .mk-card-client {
    font-size: 10.5px;
  }

  .mk-card-title {
    font-size: 16px;
    margin: 6px 0 8px;
  }

  .mk-card-desc {
    font-size: 12.5px;
    margin-bottom: 12px;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .mk-card-tags {
    padding-top: 10px;
    gap: 4px;
  }

  .mk-pill {
    font-size: 10px;
    padding: 2px 6px;
  }

  /* Card Footer Mobile Stacking - Touch optimized */
  .mk-card-footer {
    padding: 12px 14px;
    gap: 10px;
  }

  .mk-card-footer-btns {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .mk-card-footer-btns .mk-btn {
    flex: 1;
    justify-content: center;
    height: 40px;
    font-size: 13px;
    padding: 0 10px;
  }

  .mk-card-footer-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 8px;
  }

  .mk-card-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
  }

  .mk-card-actions .mk-btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--mk-surface-3);
    border: 1px solid var(--mk-border);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Modals & Dialogs */
  .mk-modal-overlay {
    padding: 10px !important;
  }

  .mk-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94vh !important;
    margin: 0 !important;
    border-radius: 14px !important;
    display: flex;
    flex-direction: column;
  }

  .mk-modal-header {
    padding: 14px 16px !important;
  }

  .mk-modal-body {
    padding: 14px 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .mk-modal-footer {
    padding: 12px 16px !important;
    flex-direction: column-reverse;
    gap: 8px;
  }

  .mk-modal-footer .mk-btn {
    width: 100% !important;
    min-width: 0 !important;
    height: 44px;
    justify-content: center;
  }

  #mk-copy-modal-textarea {
    min-height: 160px;
    font-size: 11px;
  }

  /* Command Palette (Ctrl+K) */
  .mk-cmd-palette {
    width: 100% !important;
    max-width: 100% !important;
    margin: 8px !important;
    max-height: 85vh;
  }

  /* Forms & Card Components */
  .mk-form-card {
    padding: 16px 12px;
    margin-bottom: 16px;
    border-radius: 12px;
  }

  .mk-form-card-title {
    font-size: 14px;
    margin-bottom: 14px;
    padding-bottom: 10px;
  }

  .mk-form-row {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .mk-field-group {
    margin-bottom: 14px;
    gap: 6px;
  }

  .mk-input,
  .mk-select,
  .mk-textarea {
    min-height: 44px;
    padding: 10px 12px;
    box-sizing: border-box;
  }

  #mk-save-settings-btn,
  #mk-form-publish-btn {
    width: 100%;
    height: 46px;
    justify-content: center;
    font-size: 15px;
  }

  /* Tables & Responsive Lists */
  #mk-users-list-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }

  .mk-table {
    min-width: 580px;
  }

  #mk-users-filter {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Taxonomies Grid */
  #mk-term-list {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Toast System */
  .mk-toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .mk-toast {
    min-width: auto;
    width: 100%;
    box-sizing: border-box;
    font-size: 13px;
    padding: 12px 16px;
  }

  /* PWA Install Banner */
  .mk-pwa-popup {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}

/* ==========================================================================
   Extra-small Smartphones (max-width: 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .mk-add-text {
    display: none;
  }

  .mk-header-add-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
  }

  .mk-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

/* ==========================================================================
   Wide Displays (1440px+)
   ========================================================================== */
@media (min-width: 1440px) {
  .mk-portfolio-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1920px) {
  .mk-page-body {
    max-width: 1720px;
  }
  .mk-portfolio-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 28px;
  }
}

/* ==========================================================================
   iOS Safari Native Install Sheet & Floating Bar (App Shell)
   ========================================================================== */
.mk-ios-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mk-ios-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.mk-ios-modal-card {
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mk-ios-modal-overlay.active .mk-ios-modal-card {
  transform: translateY(0);
}

.mk-ios-modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  margin-bottom: 20px;
}

.mk-ios-app-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  border: 1px solid rgba(255, 106, 0, 0.4);
  box-shadow: 0 4px 16px rgba(255, 106, 0, 0.25);
  flex-shrink: 0;
}

.mk-ios-header-text {
  flex: 1;
  min-width: 0;
}

.mk-ios-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 4px 0;
}

.mk-ios-sub {
  font-size: 12px;
  color: #8A8A8A;
  margin: 0;
  line-height: 1.4;
}

.mk-ios-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #8A8A8A;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.mk-ios-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.mk-ios-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: #1c1c1c;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
}

.mk-ios-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--mk-primary, #FF6A00);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.mk-ios-step-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mk-ios-step-text {
  font-size: 13px;
  color: #D1D5DB;
  line-height: 1.4;
}

.mk-ios-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  width: fit-content;
}

.mk-ios-badge-blue {
  background: rgba(10, 132, 255, 0.15);
  color: #5AC8FA;
  border: 1px solid rgba(10, 132, 255, 0.3);
}

.mk-ios-badge-orange {
  background: rgba(255, 106, 0, 0.15);
  color: #FF6A00;
  border: 1px solid rgba(255, 106, 0, 0.3);
}

.mk-ios-bottom-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #FF6A00;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

.mk-ios-pulse-arrow {
  font-size: 16px;
  animation: mkBounceDown 1.2s infinite ease-in-out;
}

.mk-ios-done-btn {
  width: 100%;
  background: var(--mk-primary, #FF6A00);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mk-ios-done-btn:hover {
  background: #e05e00;
}

/* Floating iOS Bottom Bar */
.mk-pwa-ios-bar {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 106, 0, 0.4);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 106, 0, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: mkSlideUp 0.3s ease;
}

.mk-pwa-ios-bar-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.mk-pwa-ios-bar-text {
  flex: 1;
  min-width: 0;
}

.mk-pwa-ios-bar-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mk-pwa-ios-bar-sub {
  font-size: 11px;
  color: #8A8A8A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mk-pwa-ios-bar-btn {
  background: var(--mk-primary, #FF6A00);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

.mk-pwa-ios-bar-close {
  background: none;
  border: none;
  color: #8A8A8A;
  font-size: 16px;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
