/* Burgos Studio UI 2.0: compact, responsive rules layered over the existing app. */
:root {
  --side: 220px;
  --ui-radius-card: 16px;
  --ui-space: 12px;
}

html { min-width: 320px; overflow-x: clip; }
body { min-width: 320px; overflow-x: clip; font-size: 13px; }
.app { width: min(1880px, calc(100% - 20px)); min-height: calc(100dvh - 20px); margin: 10px auto; gap: 12px; }
.sidebar { left: max(10px, calc((100vw - 1880px) / 2 + 10px)); width: var(--side); top: 10px; bottom: 10px; height: calc(100dvh - 20px); padding: 12px 10px; gap: 10px; transform: none; }
.main { width: auto; min-width: 0; margin-left: var(--side); padding: 0 10px 24px; }
.topbar { min-height: 56px; height: 56px; gap: 9px; padding: 0 10px; }
.history-actions .icon-btn, .top-actions .icon-btn { width: 36px; height: 36px; border-radius: 11px; }
.search { min-width: 120px; max-width: 620px; }
.search input { min-height: 38px; padding-block: 8px; border-radius: 11px; }
.top-actions { gap: 6px; }
.page-head { gap: 12px; padding: 16px 2px 12px; }
.page-head h1 { font-size: clamp(22px, 2.4vw, 32px); }
.page-head p { max-width: 72ch; font-size: 13px; }
.page-head .actions { gap: 7px; }
.page-head .actions .btn, .dashboard-primary-actions .btn { min-height: 36px; }
.page-head .page-title-row { gap: 10px; margin-bottom: 3px; }
.page-head .page-title-row .page-illustration { flex-basis: 44px !important; width: 44px !important; height: 44px !important; border-radius: 13px; }

/* Shared compact surfaces and readable controls across every existing module. */
.card, .catalog-card, .tracking-card, .agenda-card, .workflow-card, .settings-nav, .settings-content, .ops-panel, .area-project-row, .project-secondary { border-radius: var(--ui-radius-card); }
.card-head { min-height: 46px; padding: 11px 14px; gap: 10px; }
.card-body { padding: 13px 14px; }
.card-head h3 { font-size: 13px; }
.card-head p { font-size: 10px; line-height: 1.4; }
.btn { min-height: 36px; padding: 8px 12px; border-radius: 11px; }
.input, .select, .textarea { min-height: 39px; border-radius: 10px; }
.field { min-width: 0; }
.table-wrap { max-width: 100%; border-radius: 13px; overscroll-behavior-inline: contain; }
.table { max-width: 100%; }
.table th, .table td { padding: 9px 11px; }
.modal { width: min(980px, calc(100vw - 28px)); max-height: min(90dvh, 900px); border-radius: 18px; }
.modal-head, .modal-body, .modal-foot { padding: 13px 16px; }
.toast { max-width: min(420px, calc(100vw - 28px)); }

/* Dense dashboard hierarchy based on the supplied control-center reference. */
.dashboard-page { padding: 0 2px 20px; }
.dashboard-topline { gap: 14px; padding: 14px 3px 12px; }
.dashboard-welcome h1 { font-size: clamp(26px, 2.5vw, 36px); }
.dashboard-welcome p { font-size: 14px; }
.dashboard-primary-actions { gap: 7px; }
.dashboard-primary-actions .btn { padding-inline: 12px; }
.onboarding-card { margin-bottom: 10px !important; }
.dashboard-primary-metrics { gap: 10px; margin-bottom: 11px; }
.dashboard-primary-metrics .metric-card { min-height: 112px; padding: 12px 14px; border-radius: 16px; }
.dashboard-primary-metrics .metric-card > strong { font-size: clamp(16px, 1.4vw, 21px); }
.metric-icon { width: 38px; height: 38px; margin-bottom: 8px; border-radius: 12px; }
.metric-art { width: 48px; height: 48px; right: 8px; bottom: 8px; }
.dashboard-middle-row, .dashboard-bottom-row { gap: 11px; margin-bottom: 11px; }
.dashboard-page .card { border-radius: 17px; }
.dashboard-page .card-head { min-height: 54px; padding: 10px 13px; }
.dashboard-page .card-body { padding: 12px 13px; }
.dashboard-title-icon { width: 36px; height: 36px; border-radius: 12px; }
.finance-summary { min-height: 170px; gap: 12px; }
.finance-donut { width: min(100%, 170px); }
.dashboard-agenda-event { min-height: 112px; padding: 9px; }
.dashboard-quick { min-height: 54px; }

/* Tablet and small laptop: preserve labels and keep content within the viewport. */
@media (max-width: 1180px) and (min-width: 821px) {
  :root { --side: 214px; }
  .sidebar { left: max(8px, calc((100vw - 1880px) / 2 + 8px)); width: var(--side); }
  .brand-copy, .nav-btn span, .nav-group h4, .mini-company { display: block; }
  .sidebar { align-items: stretch; }
  .nav-btn { justify-content: flex-start; min-height: 36px; padding: 6px 8px; gap: 7px; }
  .nav-3d-icon { width: 30px !important; height: 30px !important; flex-basis: 30px !important; }
  .main { margin-left: var(--side); }
  .dashboard-primary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-lower { grid-template-columns: minmax(0, 1.1fr) minmax(270px, .9fr); }
  .page-head .actions { flex-wrap: wrap; }
}

@media (max-width: 900px) {
  .dashboard-middle-row, .dashboard-bottom-row, .dashboard-lower { grid-template-columns: minmax(0, 1fr); }
  .dashboard-primary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .company-insights, .project-layout, .contract-layout, .settings-shell, .calendar-shell, .photo-gallery-layout, .workflow-board, .ops-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Phone: drawer navigation, two-column KPI cards, stacked actions, no page-wide overflow. */
@media (max-width: 820px) {
  .app { display: block !important; width: 100%; min-height: 100dvh; margin: 0; }
  .sidebar { left: max(-292px, -86vw); top: 0; bottom: 0; width: min(86vw, 292px); height: 100dvh; min-height: 0; z-index: 100; border-radius: 0 20px 20px 0; padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom)); transform: none; transition: left .18s ease; }
  .sidebar.open { left: 0; transform: none; }
  .sidebar-scrim { z-index: 90; }
  .main { width: 100%; min-height: 100dvh; margin-left: 0; padding: 0 12px max(24px, env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 80; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; grid-template-areas: "menu search actions"; min-height: 56px; height: auto; margin: 0 -12px 8px; padding: 7px 10px; border-radius: 0 0 15px 15px; }
  .mobile-menu { display: grid; grid-area: menu; width: 36px; height: 36px; }
  .history-actions { display: none; }
  .search { display: block; grid-area: search; width: 100%; min-width: 0; max-width: none; }
  .search input { min-height: 36px; padding: 7px 8px 7px 34px; font-size: 12px; }
  .search .icon { left: 10px; top: 10px; width: 16px; height: 16px; }
  .search-shortcut { display: none; }
  .top-actions { grid-area: actions; margin-left: 0; gap: 4px; }
  .top-actions .icon-btn { width: 34px; height: 34px; }
  .top-actions > .icon-btn:first-child { display: none; }
  .profile { display: flex; padding: 2px; border: 0; background: transparent; }
  .profile .profile-copy { display: none; }
  .avatar { width: 32px; height: 32px; }
  .page-head { align-items: flex-start; flex-wrap: wrap; gap: 8px; padding: 12px 0 10px; }
  .page-head > div:first-child { min-width: 0; }
  .page-head p { font-size: 12px; }
  .page-head .actions { width: 100%; display: flex; flex-wrap: wrap; }
  .page-head .actions .btn { flex: 1 1 130px; }
  .page-head .page-title-row .page-illustration { width: 40px !important; height: 40px !important; flex-basis: 40px !important; border-radius: 12px; }
  .dashboard-topline { display: flex; flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 0 10px; }
  .dashboard-primary-actions { justify-content: stretch; }
  .dashboard-primary-actions .btn { flex: 1 1 0; justify-content: center; }
  .dashboard-primary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dashboard-primary-metrics .metric-card { min-width: 0; min-height: 100px; padding: 10px; }
  .dashboard-primary-metrics .metric-card > strong { max-width: 100%; font-size: clamp(14px, 4vw, 18px); overflow-wrap: anywhere; }
  .dashboard-primary-metrics .metric-card > span, .dashboard-primary-metrics .metric-card > strong, .dashboard-primary-metrics .metric-card > small { width: calc(100% - 34px); }
  .metric-art { width: 38px; height: 38px; opacity: .42; }
  .dashboard-page .card-head, .dashboard-page .card-body { padding: 11px; }
  .dashboard-lower { gap: 9px; }
  .dashboard-chart-card .chart { min-height: 150px; }
  .finance-summary { grid-template-columns: minmax(105px, .8fr) minmax(0, 1fr); min-height: 135px; gap: 8px; padding: 0; }
  .finance-donut { width: min(100%, 140px); padding: 9px; }
  .finance-legend { gap: 10px; }
  .dashboard-agenda-event { grid-template-columns: 56px minmax(0, 1fr) 48px; gap: 7px; min-height: 92px; }
  .dashboard-event-art { width: 46px; height: 54px; }
  .dashboard-area-row { grid-template-columns: 30px minmax(70px, .8fr) minmax(40px, 1fr) 24px; gap: 6px; }
  .dashboard-area-row small { display: none; }
  .grid, .stats, .project-stats, .equip-stats, .form-grid, .form-grid.three, .builder, .area-admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2, .span-3 { grid-column: 1 / -1; }
  .table-wrap { width: 100%; max-width: 100%; overflow-x: auto; }
  .table { min-width: 620px; }
  .modal { width: calc(100vw - 20px); max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); margin: 10px; }
  .modal-head, .modal-body, .modal-foot { padding: 11px 12px; }
}

@media (max-width: 560px) {
  .main { padding-inline: 9px; }
  .topbar { margin-inline: -9px; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 6px; padding-inline: 8px; }
  .mobile-menu, .top-actions .icon-btn { width: 32px; height: 32px; }
  .top-actions { gap: 2px; }
  .avatar { width: 30px; height: 30px; }
  .page-head h1 { font-size: clamp(21px, 6.8vw, 28px); }
  .page-head .page-title-row { gap: 8px; }
  .dashboard-welcome h1 { font-size: clamp(24px, 7.2vw, 31px); }
  .dashboard-primary-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dashboard-primary-actions .btn { min-width: 0; padding: 7px 8px; font-size: 11px; }
  .dashboard-primary-metrics .metric-card { min-height: 94px; padding: 9px; }
  .dashboard-primary-metrics .metric-card > span { font-size: 10px; }
  .dashboard-primary-metrics .metric-card > small { font-size: 9px; line-height: 1.25; }
  .dashboard-primary-metrics .metric-card > strong { font-size: clamp(13px, 4.3vw, 16px); }
  .metric-icon { width: 31px; height: 31px; margin-bottom: 6px; }
  .metric-edit { opacity: 1; width: 25px; height: 25px; top: 5px; right: 5px; }
  .dashboard-page .card-head h3 { font-size: 12px; }
  .dashboard-page .card-head p { font-size: 9px; }
  .dashboard-title-icon { width: 31px; height: 31px; border-radius: 10px; }
  .dashboard-quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-quick { padding: 7px; gap: 6px; }
  .dashboard-quick-icon { width: 30px; height: 30px; }
  .finance-summary { grid-template-columns: minmax(95px, .75fr) minmax(0, 1fr); }
  .finance-donut { width: min(100%, 118px); padding: 8px; }
  .finance-donut b { font-size: 13px; }
  .finance-legend b, .finance-legend strong { font-size: 10px; }
  .dashboard-finance-foot { flex-wrap: wrap; gap: 7px; font-size: 9px; }
  .dashboard-agenda-event { grid-template-columns: 48px minmax(0, 1fr); }
  .dashboard-event-art { display: none; }
  .dashboard-date-tile { min-height: 68px; }
  .dashboard-date-tile b { font-size: 22px; }
  .grid, .stats, .project-stats, .equip-stats, .form-grid, .form-grid.three, .builder, .area-admin-stats { grid-template-columns: minmax(0, 1fr); }
  .span-2, .span-3 { grid-column: auto; }
  .card-head { align-items: flex-start; flex-wrap: wrap; }
  .card-head > .toolbar, .card-head > .actions { width: 100%; flex-wrap: wrap; }
  .card-head > .toolbar .btn, .card-head > .actions .btn { flex: 1 1 120px; }
  .form-actions, .wizard-actions { flex-wrap: wrap; gap: 7px; }
  .form-actions .btn, .wizard-actions .btn { flex: 1 1 130px; }
  .tab-list, .tabs, .settings-tabs, .equipment-tabs { overflow-x: auto; max-width: 100%; flex-wrap: nowrap; scrollbar-width: thin; }
  .tab-list > *, .tabs > *, .settings-tabs > *, .equipment-tabs > * { flex: 0 0 auto; }
}

@media (max-width: 360px) {
  .topbar { grid-template-columns: 31px minmax(0, 1fr) auto; gap: 4px; }
  .top-actions .icon-btn { width: 29px; height: 29px; }
  .search input { font-size: 11px; }
  .dashboard-primary-actions { grid-template-columns: 1fr; }
  .dashboard-area-row { grid-template-columns: 27px minmax(60px, .8fr) minmax(35px, 1fr) 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
