/* ══════════════════════════════════════════════════════════
   GOLD STANDARD MOBILE — Auto-resolution, safe areas, fluid
   Asociație de Proprietari — Responsive System v4
══════════════════════════════════════════════════════════ */

/* ─── 1. FLUID FOUNDATION ─────────────────────────────── */

html {
  /* Fluid font: 14px@320px → 16px@768px */
  font-size: clamp(14px, calc(14px + 2 * ((100vw - 320px) / 448)), 16px);
  scroll-behavior: smooth;
  overscroll-behavior: none;
}

body {
  overscroll-behavior-y: contain;
  padding-top: env(safe-area-inset-top);
}

* {
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

/* Prevent iOS zoom on input focus */
/* ── mc-wrap: ascuns implicit, vizibil doar pe mobil via @media ── */
.mc-wrap {
  display: none;
}

@media (max-width: 768px) {

  input,
  select,
  textarea {
    font-size: max(16px, 1rem) !important;
  }
}

/* ─── 2. HAMBURGER BUTTON ──────────────────────────────── */

.btn-hamburger {
  display: none;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.4rem;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-hamburger:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.95);
}

/* ─── 3. SIDEBAR OVERLAY ───────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* ─── 4. TABLET: ≤992px ────────────────────────────────── */

@media (max-width: 992px) {
  header {
    padding: 0 1rem;
    height: 56px;
  }

  .app {
    height: calc(100vh - 56px);
  }

  aside {
    max-height: calc(100vh - 56px);
  }

  .header-meta,
  .user-name,
  .user-role-badge {
    display: none;
  }

  .btn-hamburger {
    display: flex;
  }

  aside {
    position: fixed;
    left: -270px;
    top: 0;
    bottom: 0;
    z-index: 1001;
    width: 270px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.4);
    padding-top: env(safe-area-inset-top);
    overflow-y: auto;
  }

  aside.mobile-active {
    transform: translateX(270px);
  }

  main {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .semnatura-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .portal-hero {
    flex-direction: column;
    padding: 1.5rem;
    text-align: center;
  }

  .portal-status {
    margin-left: 0;
    text-align: center;
    margin-top: 1rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── 5. MOBILE: ≤600px ────────────────────────────────── */

@media (max-width: 600px) {

  /* Layout */
  .stat-grid,
  .grid-stack,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .page-header>.btn,
  .page-actions>.btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .logo-sub {
    display: none;
  }

  .logo-text {
    font-size: 0.9rem;
  }

  .btn-hamburger {
    display: none !important;
  }

  /* Models & Cards */
  .card {
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    box-shadow: none;
    border: 1px solid var(--border-light);
  }

  .stat-card {
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    box-shadow: none;
    border: 1px solid var(--border-light);
  }

  .modal {
    padding: 1.5rem;
    width: calc(100vw - 1rem);
    border-radius: var(--radius-lg);
    margin: 0.5rem auto;
  }

  .modal-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding-top: 1rem;
  }

  /* Buttons — touch targets (min 48px is ideal, using 44px as baseline) */
  .btn,
  .modal-footer .btn {
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    border-radius: var(--radius-md);
    width: 100%;
    justify-content: center;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.5rem 0.8rem;
  }

  /* Form elements — 48px touch targets for mobile */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    min-height: 48px;
    padding: 0.75rem 0.85rem;
    border-radius: var(--radius-sm);
    width: 100%;
    font-size: 16px !important;
    /* Prevents iOS zoom */
  }

  /* Paper theme explicitly keeps square borders on mobile */
  [data-theme="paper"] input[type="text"],
  [data-theme="paper"] input[type="number"],
  [data-theme="paper"] input[type="date"],
  [data-theme="paper"] input[type="email"],
  [data-theme="paper"] input[type="password"],
  [data-theme="paper"] select,
  [data-theme="paper"] textarea {
    border-radius: 0 !important;
  }

  .form-group {
    margin-bottom: 0.9rem;
  }

  .form-group label {
    font-size: 0.78rem;
  }

  /* Tables */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }

  table {
    font-size: 0.78rem;
  }

  thead th {
    padding: 0.5rem;
    font-size: 0.68rem;
    white-space: nowrap;
    line-height: 1.2;
  }

  tbody td {
    padding: 0.45rem 0.5rem;
  }

  /* Simple Responsive Tables (for reports/analytics) */
  .rt-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .rt-table table {
    min-width: 450px;
    /* Force scroll if too many columns */
  }

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

  /* Search bar */
  .search-bar {
    flex-direction: column;
    gap: 0.4rem;
  }

  .search-bar select,
  .search-bar input {
    width: 100% !important;
    flex: none !important;
    max-width: 100% !important;
    min-height: 44px;
  }

  /* ══ AUTO MOBILE CARDS ══════════════════════════════════
     Tabelele dispar, apar carduri mobile la ≤600px
  ═══════════════════════════════════════════════════════ */

  .mc-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* Ascunde table-wrap-urile care au un mc-wrap sibling (CSS :has) */
  .table-wrap:has(+ .mc-wrap) {
    display: none !important;
  }

  /* Fallback explicit pentru browsere fără :has() */
  #panel-proprietari .table-wrap,
  #panel-apartamente .table-wrap,
  #tab-cote-cheltuieli .table-wrap,
  #tab-cote-calcul .table-wrap,
  #tab-restante-auto .table-wrap,
  #panel-dovezi-op .table-wrap,
  #panel-incasari .table-wrap,
  #panel-plati-mele .table-wrap,
  #panel-transparenta .table-wrap,
  #panel-contoare .table-wrap {
    display: none !important;
  }

  /* Card container */
  .mc-card {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-left: 6px solid var(--teal);
    border-radius: var(--radius-md);
    padding: 1.15rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.15s ease;
    will-change: transform;
    margin-bottom: 0.4rem;
    overflow: hidden;
  }

  .mc-card:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: none;
    background: var(--cream);
  }

  [data-theme="paper"] .mc-card {
    border-radius: 2px;
    border-left: 4px solid var(--gold);
    box-shadow: 2px 3px 0 rgba(44, 24, 16, 0.08);
  }

  .mc-card.urgent {
    border-left-color: #c0392b;
  }

  .mc-card.success {
    border-left-color: #27ae60;
  }

  .mc-card.warning {
    border-left-color: var(--gold);
  }

  /* Card header row */
  .mc-head {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-bottom: 0.5rem;
  }

  /* Apartment/number pill */
  .mc-pill {
    background: var(--navy);
    color: var(--gold-light, #e8c96e);
    font-weight: 700;
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 5px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.6;
    letter-spacing: 0.03em;
  }

  [data-theme="paper"] .mc-pill {
    font-family: 'Courier Prime', monospace;
    border-radius: 0;
    border: 1px solid var(--gold);
    background: rgba(44, 24, 16, 0.85);
  }

  /* Main info area */
  .mc-main {
    flex: 1;
    min-width: 0;
  }

  .mc-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--navy);
    line-height: 1.25;
    word-break: break-word;
  }

  [data-theme="paper"] .mc-name {
    font-family: 'Playfair Display', serif;
  }

  .mc-sub {
    font-size: 0.73rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
  }

  /* Right amount/status */
  .mc-right {
    margin-left: auto;
    text-align: right;
    flex-shrink: 0;
  }

  .mc-amount {
    font-weight: 700;
    font-size: 0.94rem;
    color: var(--navy);
    white-space: nowrap;
  }

  [data-theme="paper"] .mc-amount {
    font-family: 'Courier Prime', monospace;
  }

  .mc-amount.neg {
    color: #c0392b;
  }

  .mc-amount.pos {
    color: #27ae60;
  }

  /* Fields grid */
  .mc-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px 8px;
    margin: 0.3rem 0 0.4rem;
    border-top: 1px solid var(--border);
    padding-top: 0.35rem;
  }

  .mc-field {
    padding: 3px 0;
  }

  .mc-field.wide {
    grid-column: 1 / -1;
  }

  .mc-label {
    font-size: 0.59rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    line-height: 1;
    margin-bottom: 1px;
  }

  [data-theme="paper"] .mc-label {
    font-family: 'Courier Prime', monospace;
  }

  .mc-val {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--navy);
    line-height: 1.3;
  }

  /* Compact Card for Reports */
  .mc-card.compact {
    padding: 0.75rem;
  }

  .mc-card.compact .mc-head {
    margin-bottom: 0.25rem;
  }

  .mc-card.compact .mc-fields {
    margin-top: 0.15rem;
    padding-top: 0.2rem;
  }

  /* Progress bar */
  .mc-bar-wrap {
    height: 6px;
    background: var(--cream-dark);
    border-radius: 3px;
    overflow: hidden;
    margin: 0.35rem 0 2px;
  }

  [data-theme="paper"] .mc-bar-wrap {
    border-radius: 0;
  }

  .mc-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--teal);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mc-bar-fill.warn {
    background: var(--gold);
  }

  .mc-bar-fill.danger {
    background: #c0392b;
  }


  /* ── Rând info sub mc-head (status cont etc) ── */
  .mc-row-info {
    font-size: 0.71rem;
    color: var(--text-muted);
    margin: 2px 0 6px;
    padding-left: 2px;
  }

  .mc-dot.ok {
    color: #27ae60;
    font-weight: 600;
  }

  .mc-dot.off {
    color: #95a5a6;
  }

  /* ── mc-card compact variant ── */
  .mc-card {
    /* ensure min touch target height */
    min-height: 80px;
  }

  .mc-pill {
    min-width: 40px;
    text-align: center;
  }

  /* Action buttons row */
  .mc-actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--border);
  }

  .mc-actions .btn {
    flex: 1;
    min-width: 64px;
    font-size: 0.76rem;
    padding: 0.4rem 0.5rem;
    min-height: 38px;
    justify-content: center;
    text-align: center;
  }

  /* ── Bottom Navigation Bar (admin phones) ── */
  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(10, 20, 38, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    /* Safe area for iPhone home indicator */
    height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    justify-content: space-around;
    align-items: center;
    padding-top: 6px;
  }

  .bn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    height: 100%;
    cursor: pointer;
    border: none;
    background: transparent;
    color: #8a9ab8;
    font-size: clamp(0.55rem, 1.5vw, 0.65rem);
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    transition: color 0.2s, transform 0.2s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    padding: 0 4px;
  }

  .bn-item .bn-icon {
    font-size: clamp(1.2rem, 5vw, 1.4rem);
    line-height: 1;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-bottom: 2px;
  }

  .bn-item:active {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
  }

  .bn-item:active .bn-icon {
    transform: scale(0.9);
  }

  .bn-item.active {
    color: var(--teal-light);
  }

  .bn-item.active .bn-icon {
    transform: translateY(-2px);
  }

  /* Active indicator dot */
  .bn-item.active::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--teal-light);
    box-shadow: 0 0 8px var(--teal-light);
  }

  /* Pad main so content isn't hidden behind bottom nav */
  main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }

  /* Portal hero */
  .portal-hero {
    flex-direction: column;
    padding: 1.25rem;
    text-align: center;
    gap: 0.75rem;
  }

  .portal-apt-badge {
    margin: 0 auto;
  }

  .portal-status {
    margin: 0 auto;
  }

  /* Login */
  .login-box {
    padding: 2rem 1.5rem;
    border-radius: 16px;
    width: calc(100vw - 2rem);
    max-width: 100%;
  }

  /* Page actions */
  .page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }

  .page-actions .btn {
    flex: 1;
    min-width: 110px;
    justify-content: center;
    min-height: 42px;
  }

  /* Nav items touch targets */
  .nav-item {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 44px;
  }

  /* Hide scrollbars on mobile */
  .table-wrap::-webkit-scrollbar,
  aside::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}

/* ─── 6. SMALL PHONES: ≤375px ──────────────────────────── */

@media (max-width: 375px) {
  .mc-pill {
    font-size: 0.62rem;
    padding: 2px 6px;
  }

  .mc-name {
    font-size: 0.84rem;
  }

  .mc-amount {
    font-size: 0.86rem;
  }

  .mc-actions .btn {
    font-size: 0.72rem;
    padding: 0.35rem 0.4rem;
  }

  .card-title {
    font-size: 0.95rem;
  }

  .bn-item {
    font-size: 0.48rem;
  }

  .bn-item .bn-icon {
    font-size: 1.05rem;
  }
}

/* ─── 7. LANDSCAPE MOBILE ──────────────────────────────── */

@media (max-width: 768px) and (orientation: landscape) {
  .login-box {
    padding: 1.5rem;
    max-height: 90svh;
    overflow-y: auto;
  }

  .modal {
    max-height: calc(100svh - 1rem);
  }

  #bottom-nav {
    height: calc(48px + env(safe-area-inset-bottom));
  }

  main {
    padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important;
  }

  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

/* ─── 8. FLOATING MENU BUBBLE (proprietari only) ──────── */

#btn-floating-menu {
  display: none;
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  right: calc(1.5rem + env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  background: var(--navy);
  color: var(--gold);
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  animation: bubbleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  -webkit-tap-highlight-color: transparent;
}

@keyframes bubbleIn {
  from {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
  }

  to {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

/* ─── 9. PREFERS REDUCED MOTION ────────────────────────── */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── 10. PRINT ─────────────────────────────────────────── */

@media print {

  aside,
  header,
  #bottom-nav,
  #btn-floating-menu,
  .btn-hamburger,
  .sidebar-overlay,
  .mc-actions,
  .page-header .btn {
    display: none !important;
  }

  main {
    padding: 0 !important;
  }
}