/* Ultra-Compact High-Performance Stylesheet for Construction Progress Tracker (Mobile & Desktop) */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --success-dark: #059669;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-dark: #d97706;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.4;
}

body {
  display: flex;
  flex-direction: column;
}

/* ======================================================== */
/* 0. STRICT FULLSCREEN LOGIN BARRIER                       */
/* ======================================================== */
.login-fullscreen-barrier {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0f172a;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.login-box-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3);
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

/* ======================================================== */
/* 1. ULTRA-COMPACT HEADER (~42px)                          */
/* ======================================================== */
header.compact-header {
  flex-shrink: 0;
  height: auto;
  min-height: calc(42px + env(safe-area-inset-top));
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap;
  width: 100%;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: 4px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  z-index: 100;
  box-shadow: var(--shadow-sm);
  gap: 5px;
}

header.compact-header::-webkit-scrollbar {
  display: none;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 5px;
}

.nav-right {
  margin-left: auto;
}

.nav-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: #f1f5f9;
  border-color: var(--border-dark);
}

.nav-selector-btn {
  background: #ffffff;
  border-color: var(--primary);
  color: var(--primary);
  max-width: 180px;
}

.nav-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.nav-caret {
  font-size: 10px;
  opacity: 0.7;
}

.nav-stat-btn {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
  padding: 0 6px;
}

.stat-dot-approved {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.stat-dot-pending {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
}

.nav-user-avatar {
  font-size: 14px;
}

.nav-user-name {
  max-width: 65px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

/* History Notification Banner */
.compact-history-banner {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  height: 26px;
  min-height: 26px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  z-index: 90;
}

.btn-history-reset {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #b45309;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  cursor: pointer;
}

/* ======================================================== */
/* 2. FULL-SCREEN MATRIX CONTAINER                          */
/* ======================================================== */
main.matrix-fullscreen-wrapper {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  padding: 0;
}

.matrix-container {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #ffffff;
}

table.matrix-table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 11px;
}

/* ======================================================== */
/* 3. STICKY HEADERS & STICKY FLOOR COLUMN                 */
/* ======================================================== */
/* Header 1: Systems Row */
table.matrix-table thead tr.system-header-row th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border-dark);
  border-right: 1px solid var(--border);
  height: 24px;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: 700;
  color: #1e293b;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* Header 2: Work Types Row */
table.matrix-table thead tr.work-header-row th {
  position: sticky;
  top: 24px;
  z-index: 10;
  background: #f8fafc;
  border-bottom: 2px solid var(--border-dark);
  border-right: 1px solid var(--border);
  height: 48px;
  width: 52px;
  min-width: 50px;
  max-width: 56px;
  padding: 3px 2px;
  font-size: 10px;
  line-height: 1.15;
  color: #475569;
  font-weight: 600;
  text-align: center;
  vertical-align: middle;
  word-break: break-word;
  overflow: hidden;
}

/* Floor Column: Clean (48px) & Sticky Left */
table.matrix-table th.col-floor,
table.matrix-table td.col-floor {
  position: sticky;
  left: 0;
  z-index: 5;
  width: 48px;
  min-width: 48px;
  max-width: 52px;
  background: #ffffff;
  border-right: 2px solid var(--border-dark);
  border-bottom: 1px solid var(--border);
  text-align: center;
  padding: 2px 2px;
  user-select: none;
}

table.matrix-table thead th.col-floor {
  z-index: 20;
  background: #e2e8f0;
}

.floor-cell-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.floor-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
}

.floor-pct {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1;
  margin-top: 2px;
}

.floor-pct.pct-100 {
  color: #059669;
  font-weight: 700;
}

/* Data Cells */
table.matrix-table td {
  width: 52px;
  min-width: 50px;
  max-width: 56px;
  height: 38px;
  padding: 2px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

/* ======================================================== */
/* 4. COMPACT STATUS TILES                                  */
/* ======================================================== */
.cell-tile {
  width: 100%;
  height: 100%;
  min-height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.1s ease;
  user-select: none;
}

.cell-tile:active {
  transform: scale(0.92);
}

/* Status 0: Pending */
.cell-tile.cell-status-0 {
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  color: #cbd5e1;
}
.cell-tile.cell-status-0 .cell-status-icon {
  font-size: 16px;
  line-height: 1;
}

/* Status 1: Completed by Worker (Amber) */
.cell-tile.cell-status-1 {
  background-color: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
}
.cell-tile.cell-status-1 .cell-status-icon {
  font-size: 14px;
  line-height: 1;
}

/* Status 2: Approved by Foreman (Green) */
.cell-tile.cell-status-2 {
  background-color: #d1fae5;
  border: 1px solid #10b981;
  color: #065f46;
}
.cell-tile.cell-status-2 .cell-status-icon {
  font-size: 13px;
  line-height: 1;
}

/* Status -1: Not Applicable / Disabled (Striped Gray) */
.cell-tile.cell-status-na,
.cell-tile.cell-status--1 {
  background: repeating-linear-gradient(
    45deg,
    #f8fafc,
    #f8fafc 4px,
    #e2e8f0 4px,
    #e2e8f0 8px
  );
  border: 1px dashed #cbd5e1;
  color: #94a3b8;
  opacity: 0.85;
}
.cell-tile.cell-status-na:hover,
.cell-tile.cell-status--1:hover {
  opacity: 1;
  border-color: #94a3b8;
}
.cell-tile.cell-status-na .cell-status-icon,
.cell-tile.cell-status--1 .cell-status-icon {
  font-size: 14px;
  font-weight: 800;
  color: #94a3b8;
}

/* Applicability floor checkbox item */
.applicability-floor-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.applicability-floor-item:hover {
  background: #f1f5f9;
}
.applicability-floor-item.excluded {
  background: #f1f5f9;
  border-style: dashed;
  color: #94a3b8;
  opacity: 0.75;
}
.applicability-floor-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Mini Corner Badges */
.tile-badge-left {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 8px;
  line-height: 1;
}

.tile-badge-right {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 8px;
  line-height: 1;
}

/* Bottom Summary Footer */
table.matrix-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: #f1f5f9;
  border-top: 2px solid var(--border-dark);
  border-right: 1px solid var(--border);
  height: auto;
  min-height: 26px;
  padding: 2px 1px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  font-weight: 700;
  font-size: 9px;
  text-align: center;
  vertical-align: middle;
}

table.matrix-table tfoot td.col-floor {
  z-index: 20;
  background: #e2e8f0;
  font-size: 10px;
}

/* ======================================================== */
/* 5. SYSTEMS FILTER LIST                                   */
/* ======================================================== */
.system-filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.system-filter-item:hover {
  background: #f1f5f9;
}

.system-filter-item.active {
  background: #eff6ff;
  border-color: var(--primary);
}

.system-filter-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}

.system-filter-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ======================================================== */
/* 6. MODALS & BOTTOM SHEETS                                */
/* ======================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 12px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

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

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0);
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
}
.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  gap: 2px;
}

.modal-tab-btn {
  padding: 7px 11px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Section Cards Grid */
.section-cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.section-card {
  padding: 14px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.section-card:hover, .section-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.section-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.section-card-stat {
  font-size: 11px;
  color: var(--success-dark);
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #ffffff; color: var(--text-main); border-color: var(--border-dark); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-warning { background: var(--warning); color: #ffffff; }
.btn-danger { background: var(--danger); color: #ffffff; }
.btn-sm { padding: 4px 8px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.form-control {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}

/* Photos & Gallery */
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.photo-delete-btn {
  position: absolute;
  top: 3px;
  right: 3px;
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
}

/* Unified Timeline */
.unified-timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  padding-left: 24px;
}

.unified-timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border-dark);
}

.timeline-event-card {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
}

.timeline-event-icon {
  position: absolute;
  left: -24px;
  top: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--border-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
}

.timeline-event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--text-muted);
}

.timeline-event-content {
  font-size: 12px;
  color: var(--text-main);
}

.timeline-photo-preview {
  display: inline-block;
  margin-top: 5px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 100px;
  border: 1px solid var(--border);
}

.timeline-photo-preview img {
  width: 100%;
  display: block;
}

.user-role-tag {
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  background: #cbd5e1;
  color: #334155;
}
.role-admin { background: #fee2e2; color: #991b1b; }
.role-foreman { background: #fef3c7; color: #92400e; }
.role-worker { background: #dbeafe; color: #1e40af; }
.role-inspector { background: #e0e7ff; color: #3730a3; }
.role-guest { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }

/* User Management & Settings Cards */
.user-card-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  gap: 8px;
  flex-wrap: wrap;
}

.user-card-item.user-disabled {
  background: #f8fafc;
  opacity: 0.75;
}

.user-info-block {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.user-login-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.status-active-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
}

.status-disabled-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.user-actions-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px;
}

.lightbox-img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: var(--radius-md);
}

/* Floor Filter Chips */
.floors-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 4px 2px;
}

.floor-chip-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-dark);
  background: #f8fafc;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  padding: 2px 4px;
}

.floor-chip-btn:hover {
  background: #f1f5f9;
  border-color: var(--primary);
}

.floor-chip-btn.active {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #ffffff;
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.25);
}

.floor-chip-num {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
}

.floor-chip-pct {
  font-size: 9px;
  opacity: 0.85;
  margin-top: 1px;
}

.floor-chip-btn.active .floor-chip-pct {
  color: #eff6ff;
}

/* Floor Filter Active State on Header Button */
.nav-btn.filter-active {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

/* Mobile Bottom Sheets & Notch / Dynamic Island Safe Areas */
@media (max-width: 600px) {
  .modal-dialog.modal-bottom-sheet {
    align-self: flex-end;
    margin: 0;
    max-height: 85vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    transform: translateY(100%);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .modal-overlay.active .modal-dialog.modal-bottom-sheet {
    transform: translateY(0);
  }
  header.compact-header {
    gap: 4px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .nav-left, .nav-right {
    gap: 4px;
    flex-shrink: 0;
  }
  .nav-right {
    margin-left: 0;
  }
  .nav-btn {
    flex-shrink: 0;
    padding: 0 7px;
    height: 32px;
    font-size: 11px;
    gap: 3px;
  }
  .nav-selector-btn {
    max-width: 140px;
  }
  .nav-title-text {
    max-width: 110px;
  }
  .nav-user-name {
    display: none;
  }
}

/* ======================================================== */
/* 7. LANDSCAPE ORIENTATION (Dynamic Island on the side)    */
/* ======================================================== */
@media (orientation: landscape) {
  header.compact-header {
    min-height: 42px;
    padding-top: 4px;
    padding-bottom: 4px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  main.matrix-fullscreen-wrapper {
    padding-left: env(safe-area-inset-left);
    padding-right: 0;
    padding-bottom: 0;
  }
}

/* ======================================================== */
/* 8. OBJECT HIERARCHY TREE (NESTED STRUCTURE)              */
/* ======================================================== */
.hierarchy-branches-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 720px) {
  .hierarchy-branches-grid {
    grid-template-columns: 1fr;
  }
}

.hierarchy-branch-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
}

.branch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}
.branch-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-main);
}
.branch-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tree-node {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.tree-node:hover {
  border-color: #cbd5e1;
}

.tree-node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #ffffff;
  border-bottom: 1px solid #f1f5f9;
}
.tree-node-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tree-node-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tree-node-content {
  padding: 8px 10px;
}

.tags-cloud-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.hierarchy-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #334155;
  user-select: none;
}
.hierarchy-tag i {
  cursor: pointer;
  color: #94a3b8;
  font-style: normal;
  font-size: 11px;
  line-height: 1;
  padding: 1px;
}
.hierarchy-tag i:hover {
  color: var(--danger);
  font-weight: 800;
}

.btn-xs {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  line-height: 1.4;
  font-weight: 600;
}
.btn-xs:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.btn-xs-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-xs-primary:hover {
  background: var(--primary-dark);
}
.btn-xs-danger {
  color: var(--danger);
  border-color: #fecaca;
}
.btn-xs-danger:hover {
  background: #fef2f2;
  border-color: var(--danger);
}

.node-inline-adder {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.node-inline-adder input {
  font-size: 11px;
  padding: 4px 6px;
  height: 26px;
}
.node-inline-adder button {
  padding: 0 8px;
  height: 26px;
  font-size: 11px;
}
