/* ================================================
   CRM Jorge Stores - Stylesheet Responsivo
   ================================================ */

/* CSS Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    margin: 0;
    background-color: var(--bg-page);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --bg-page: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --radius: 24px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --header-height: 70px;
    --z-crm-header: 1100;
    --z-crm-obra-tabs: 1090;
    --z-crm-modal: 1300;
}

/* Layout Bento */
.container {
    width: 95%;
    max-width: 1600px;
    margin: 30px auto;
    padding: 0 15px;
}

/* Header */
header {
    background: var(--bg-card);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: var(--z-crm-header, 1100);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

header nav,
header nav.crm-topnav {
    width: 95%;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px 12px;
    box-sizing: border-box;
}

header .logo-container,
.crm-topnav__brand {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.025em;
}

/* Mobile Menu Button */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.menu-toggle:hover {
    background: var(--bg-page);
}

/* Menu topo: ver public/assets/css/crm-header.css */

@media (max-width: 1100px) and (min-width: 769px) {
    .crm-welcome {
        display: none;
    }
}

header a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: color 0.2s;
    padding: 5px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

header a:hover {
    color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

/* Cards & Grid */
.card, .kpi-card, .chart-container, .app-card { 
    background: var(--bg-card); 
    padding: 25px; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    border: 1px solid rgba(255,255,255,0.5);
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.card:hover, .app-card:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-hover); 
}

/* Grid System */
.grid-3 { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); 
    gap: 25px; 
}

.grid-2 { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 450px), 1fr)); 
    gap: 25px; 
}

/* Dashboard (index) — layout desktop original */
@media (min-width: 769px) {
    .dashboard-home .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-home .grid-2.dashboard-split {
        grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    }

    .dashboard-home .grid-3 {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    .dashboard-home .table-wrapper {
        overflow-x: auto;
        max-width: 100%;
    }

    .dashboard-home .dash-table {
        min-width: 0;
        width: 100%;
        display: table;
        border-collapse: separate;
        border-spacing: 0;
        background: var(--bg-card);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }

    .dashboard-home .dash-table thead {
        display: table-header-group;
    }

    .dashboard-home .dash-table tbody {
        display: table-row-group;
    }

    .dashboard-home .dash-table tr {
        display: table-row;
    }

    .dashboard-home .dash-table th,
    .dashboard-home .dash-table td {
        display: table-cell;
    }
}

.dashboard-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 
    gap: 25px; 
    margin-bottom: 25px; 
}

.chart-row { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr)); 
    gap: 25px; 
    margin-bottom: 25px; 
}

/* Typography */
h2 { 
    font-size: 1.8rem; 
    font-weight: 700; 
    letter-spacing: -0.03em; 
    color: #111827; 
    margin-bottom: 20px; 
}

h3 { 
    font-size: 1.2rem; 
    font-weight: 600; 
    margin-top: 0; 
    color: #374151; 
}

/* Tables - Responsive */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 10px;
    border-radius: var(--radius);
}

table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    background: var(--bg-card); 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    overflow: hidden; 
    min-width: 600px;
}

table.small-screen {
    min-width: 500px;
}

th { 
    background-color: #f9fafb; 
    color: var(--text-muted); 
    font-weight: 600; 
    text-transform: uppercase; 
    font-size: 0.75rem; 
    letter-spacing: 0.05em; 
    padding: 15px; 
    border-bottom: 1px solid #e5e7eb; 
    text-align: left; 
    white-space: nowrap;
}

td { 
    padding: 15px; 
    border-bottom: 1px solid #f3f4f6; 
    color: var(--text-main); 
    font-size: 0.9rem; 
}

tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f9fafb; }

/* Tabela → cartões no telemóvel (obras, listagens) */
.table-cards-mobile .table-wrapper {
    overflow-x: visible;
}

/* Buttons */
.button { 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px;
    background: var(--primary); 
    color: #fff; 
    padding: 10px 20px; 
    text-decoration: none; 
    border-radius: 12px; 
    font-weight: 600; 
    font-size: 0.9rem; 
    border: none; 
    cursor: pointer; 
    transition: all 0.2s; 
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2); 
    white-space: nowrap;
}

.button:hover { 
    background: var(--primary-dark); 
    transform: translateY(-1px); 
}

.btn-small { 
    padding: 6px 12px; 
    font-size: 0.8rem; 
    border-radius: 8px; 
}

.btn-danger { 
    background: #ef4444; 
    box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.2); 
}

.btn-danger:hover { 
    background: #dc2626; 
}

/* Forms */
input, select, textarea { 
    width: 100%; 
    padding: 10px 12px; 
    margin: 5px 0 15px 0; 
    display: inline-block; 
    border: 1px solid #d1d5db; 
    border-radius: 8px; 
    box-sizing: border-box; 
    background: #f9fafb; 
    transition: border 0.2s; 
    font-family: inherit; 
    font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus { 
    outline: none; 
    border-color: var(--primary); 
    background: #fff; 
}

label { 
    font-weight: 600; 
    font-size: 0.9rem; 
    color: #374151; 
    margin-bottom: 4px; 
    display: block; 
}

/* Status Badges */
.status-badge { 
    padding: 4px 10px; 
    border-radius: 20px; 
    font-size: 0.75rem; 
    font-weight: 700; 
    white-space: nowrap;
}

.status-green { background-color: #dcfce7; color: #166534; }
.status-blue { background-color: #dbeafe; color: #1e40af; }

/* Tabs */
.tab-bar { 
    border-bottom: none; 
    margin-bottom: 25px; 
    display: flex; 
    gap: 10px; 
    padding: 5px; 
    background: #e5e7eb; 
    border-radius: 16px; 
    width: fit-content; 
    flex-wrap: wrap;
}

.tab-btn { 
    background: transparent; 
    border: none; 
    padding: 8px 20px; 
    cursor: pointer; 
    font-size: 0.9rem; 
    color: var(--text-muted); 
    border-radius: 12px; 
    transition: 0.3s; 
    font-weight: 600; 
}

.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { 
    background: #fff; 
    color: var(--primary); 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1); 
}

.tab-content { display: none; animation: fadeEffect 0.5s; }
.tab-content.active { display: block; }

/* Gerir obra — separadores no fluxo da página (sticky abaixo do menu) */
.ver-obra-page.container {
    margin-top: 12px;
    margin-bottom: 16px;
}
.ver-obra-page .obra-page-header {
    margin-bottom: 10px;
    padding-bottom: 8px;
}
.ver-obra-page .obra-page-header h2 {
    margin: 0 0 4px;
    font-size: 1.35rem;
}
.ver-obra-page .obra-meta-list {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.35;
}
.ver-obra-page .obra-flash-ok,
.ver-obra-page > div[style*="margin-bottom:15px"],
.ver-obra-page > div[style*="margin-bottom: 15px"] {
    margin-bottom: 10px !important;
    padding: 8px 10px !important;
    font-size: 0.88rem;
}
.ver-obra-page .tab-content .card {
    padding: 12px 14px;
    margin-bottom: 10px;
}
.ver-obra-page .tab-content .card h3 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1.05rem;
}
.ver-obra-page .tab-content .card p {
    margin: 0 0 8px;
    font-size: 0.88rem;
}
.ver-obra-page .tab-btn {
    padding: 6px 11px;
    font-size: 0.82rem;
}
.obra-tabs-sticky-shell,
.obra-tabs-fixed-shell {
    position: sticky;
    top: var(--header-height, 70px);
    z-index: var(--z-crm-obra-tabs, 1090);
    margin: 0 0 10px;
    padding: 6px 0 8px;
    background: #f1f5f9;
    border-bottom: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}
.obra-tabs-fixed-inner {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.obra-tabs-fixed-inner .tab-bar {
    width: 100%;
    margin-bottom: 0;
    flex-wrap: wrap;
    gap: 4px;
}
.ver-obra-panels {
    padding-top: 0;
    overflow: visible;
}
.ver-obra-panels .obra-tabs-spacer {
    display: none;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0;
    padding: 0;
}
.ver-obra-panels .tab-content {
    scroll-margin-top: calc(var(--header-height, 70px) + var(--obra-tabs-offset, 56px) + 8px);
}
/* Agenda de produção — Gerir obra (desktop + mobile) */
.obra-agenda-producao {
    margin: 0 0 18px;
    padding: 16px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
}
.obra-agenda-producao__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.obra-agenda-producao__head h4 {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
}
.obra-agenda-producao__sub {
    margin: 0;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.35;
}
.obra-agenda-producao__head-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
.obra-agenda-producao__badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
}
.obra-agenda-producao__link-geral {
    font-size: 0.82rem;
    font-weight: 500;
    color: #2563eb;
    text-decoration: none;
    white-space: nowrap;
}
.obra-agenda-producao__link-geral:hover { text-decoration: underline; }
.obra-producao-agendar {
    margin: 0 0 16px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}
.obra-producao-agendar__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 14px;
}
.obra-btn-abrir-agenda {
    background: #2563eb !important;
    font-weight: 600 !important;
    min-height: 44px;
    padding: 10px 18px !important;
}
.obra-producao-agendar__proximo {
    font-size: 0.85rem;
    color: #475569;
}
.obra-producao-agendar__form {
    max-width: 480px;
}
/* Calendários CRM (agendamentos.php + agenda produção na obra) */
.crm-agenda-calendar-wrap {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    width: 100%;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
    z-index: 1;
}
.crm-agenda-calendar,
.crm-agenda-calendar-wrap .fc {
    font-family: inherit;
}
.crm-agenda-calendar .fc-toolbar,
.crm-agenda-calendar-wrap .fc-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px !important;
}
.crm-agenda-calendar .fc-toolbar-title,
.crm-agenda-calendar-wrap .fc-toolbar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
}
.crm-agenda-calendar .fc-button,
.crm-agenda-calendar-wrap .fc-button {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
    border-radius: 8px;
}
.crm-agenda-calendar .fc-col-header-cell-cushion,
.crm-agenda-calendar-wrap .fc-col-header-cell-cushion {
    font-size: 0.78rem;
    font-weight: 600;
    color: #475569;
    text-decoration: none;
}
.crm-agenda-calendar .fc-daygrid-day-frame,
.crm-agenda-calendar-wrap .fc-daygrid-day-frame {
    min-height: 128px;
}
.crm-agenda-calendar .fc-daygrid-day-number,
.crm-agenda-calendar-wrap .fc-daygrid-day-number {
    font-size: 0.88rem;
    padding: 4px 6px;
}
.crm-agenda-calendar .fc-daygrid-event,
.crm-agenda-calendar-wrap .fc-daygrid-event {
    white-space: pre-line;
    overflow: hidden;
    font-size: 0.82rem;
    line-height: 1.32;
    border-radius: 5px;
    padding: 5px 7px;
    margin: 2px 1px 0;
    max-height: none;
}
.crm-agenda-calendar .crm-agenda-ev-full,
.crm-agenda-calendar-wrap .crm-agenda-ev-full {
    white-space: pre-line;
    display: block;
    font-size: inherit;
    line-height: inherit;
    overflow: hidden;
    word-break: break-word;
    pointer-events: none;
}
.crm-agenda-calendar .fc-timegrid-event .crm-agenda-ev-full,
.crm-agenda-calendar-wrap .fc-timegrid-event .crm-agenda-ev-full {
    white-space: pre-line;
    font-size: 0.84rem;
    line-height: 1.35;
    overflow: hidden;
}
.crm-agenda-calendar .fc-popover .fc-event,
.crm-agenda-calendar-wrap .fc-popover .fc-event,
.crm-agenda-calendar .fc-popover .crm-agenda-ev-full,
.crm-agenda-calendar-wrap .fc-popover .crm-agenda-ev-full {
    white-space: pre-line !important;
    max-height: none !important;
    overflow: visible !important;
    font-size: 0.88rem;
    line-height: 1.4;
    padding: 6px 8px;
}
.crm-agenda-calendar .fc-daygrid-more-link,
.crm-agenda-calendar-wrap .fc-daygrid-more-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: #0369a1;
}
.crm-agenda-calendar .fc-scrollgrid,
.crm-agenda-calendar-wrap .fc-scrollgrid {
    border-radius: 8px;
    overflow: visible;
}
body.obra-agenda-modal-open .obra-tabs-sticky-shell,
body.obra-agenda-modal-open .obra-tabs-fixed-shell {
    z-index: 1 !important;
}
.obra-modal-agenda-producao {
    z-index: 2500;
    position: fixed;
    inset: 0;
    padding: 8px;
    box-sizing: border-box;
    overflow: hidden;
    display: none !important;
    align-items: center;
    justify-content: center;
}
.obra-modal-agenda-producao.is-open {
    display: flex !important;
}
.obra-modal-agenda-producao__content.modal-content {
    position: relative;
    width: min(1080px, calc(100vw - 16px));
    max-width: 1080px;
    margin: 0 auto;
    padding: 0;
    max-height: calc(100vh - 16px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    flex-shrink: 0;
}
html.obra-agenda-modal-open,
body.obra-agenda-modal-open {
    overflow: hidden;
}
.obra-modal-agenda-producao__inner {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 10px 14px 12px;
    box-sizing: border-box;
}
.obra-modal-agenda-producao__close {
    display: none;
}
.obra-modal-agenda-producao__obra {
    margin: 0 0 4px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #0f172a;
}
.obra-modal-agenda-producao__hint {
    margin: 0 0 6px;
    font-size: 0.78rem;
    line-height: 1.35;
    color: #64748b;
}
.obra-modal-agenda-producao__content h3,
#modalAgendaProducaoTitulo {
    margin: 0 0 4px;
    font-size: 1rem;
    padding-right: 36px;
}
.obra-agenda-producao__cal-wrap {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}
.obra-agenda-producao__cal-wrap--modal {
    max-width: none;
    width: 100%;
    padding: 4px 2px 4px;
    margin-bottom: 6px;
    overflow: hidden;
}
.obra-modal-agenda-producao .obra-producao-acao-panel {
    margin-top: 0;
    padding: 10px 12px;
}
.obra-producao-acao-panel {
    margin-top: 0;
    padding: 12px 14px;
    background: #eff6ff;
    border: 1px solid #93c5fd;
    border-radius: 12px;
}
.obra-producao-acao-panel__title {
    margin: 0 0 8px;
    font-size: 1rem;
    color: #1e40af;
}
.obra-producao-acao-panel__obra {
    margin: 0 0 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}
.obra-producao-acao-panel__acoes {
    margin-bottom: 12px;
}
.obra-producao-acao-panel__msg {
    padding: 12px;
    background: #ecfdf5;
    border-radius: 8px;
    color: #166534;
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.obra-producao-acao-panel__agendar-extra label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    display: block;
    margin-bottom: 6px;
}
.obra-producao-acao-panel__hora-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.obra-producao-acao-panel__hora-row input[type="time"] {
    flex: 1;
    min-width: 120px;
    min-height: 44px;
    margin: 0;
    padding: 10px;
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
}
#obra-calendario-producao {
    --fc-border-color: #e2e8f0;
    --fc-button-bg-color: #2563eb;
    --fc-button-border-color: #2563eb;
    --fc-button-hover-bg-color: #1d4ed8;
    --fc-button-hover-border-color: #1d4ed8;
    --fc-button-active-bg-color: #1e40af;
    --fc-button-active-border-color: #1e40af;
    --fc-today-bg-color: rgba(59, 130, 246, 0.12);
    --fc-page-bg-color: transparent;
    --fc-neutral-bg-color: #f1f5f9;
    --fc-list-event-hover-bg-color: #eff6ff;
    font-family: 'Inter', system-ui, sans-serif;
}
#obra-calendario-producao .fc-toolbar {
    margin-bottom: 12px !important;
    gap: 8px;
    flex-wrap: wrap;
}
#obra-calendario-producao .fc-toolbar-title {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: #0f172a !important;
}
#obra-calendario-producao .fc-button {
    padding: 8px 12px !important;
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    box-shadow: none !important;
    text-transform: capitalize;
}
#obra-calendario-producao .fc-button:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35) !important;
}
#obra-calendario-producao .fc-col-header-cell {
    background: #f1f5f9;
    border-color: #e2e8f0;
}
#obra-calendario-producao .fc-col-header-cell-cushion {
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    padding: 8px 4px;
    text-transform: uppercase;
}
#obra-calendario-producao .fc-daygrid-day {
    transition: background 0.15s ease;
}
#obra-calendario-producao .fc-daygrid-day-number {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 8px;
    color: #334155;
}
#obra-calendario-producao .fc-day-today .fc-daygrid-day-number {
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
    width: 1.75rem;
    text-align: center;
}
#obra-calendario-producao .fc-daygrid-day-frame {
    min-height: 52px !important;
}
.obra-agenda-producao__cal-wrap--modal #obra-calendario-producao .fc-toolbar {
    margin-bottom: 6px !important;
}
.obra-agenda-producao__cal-wrap--modal #obra-calendario-producao .fc-col-header-cell-cushion {
    padding: 6px 2px !important;
    font-size: 0.72rem !important;
}
.obra-agenda-producao__cal-wrap--modal #obra-calendario-producao .fc-daygrid-day-frame {
    min-height: 0 !important;
}
.obra-agenda-producao__cal-wrap--modal #obra-calendario-producao .fc-daygrid-day-number {
    font-size: 0.8rem !important;
    padding: 4px 6px !important;
}
.obra-agenda-producao__cal-wrap--modal #obra-calendario-producao .fc-daygrid-event {
    font-size: 0.68rem !important;
    padding: 1px 3px !important;
    margin: 1px 2px !important;
    line-height: 1.2 !important;
}
.obra-agenda-producao__cal-wrap--modal .fc-view-harness {
    overflow: hidden !important;
}
.obra-modal-agenda-producao .obra-producao-acao-panel__acoes {
    margin-bottom: 8px;
}
.obra-modal-agenda-producao .obra-producao-acao-panel__obra {
    margin-bottom: 8px;
}
.obra-modal-agenda-producao .obra-producao-acao-panel__acoes .button {
    min-height: 40px !important;
}
.obra-modal-agenda-producao .obra-producao-acao-panel__hora-row input[type="time"] {
    min-height: 38px;
    padding: 6px 8px;
}
@media (max-width: 640px) {
    .obra-modal-agenda-producao__content.modal-content {
        width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
    }
}
#obra-calendario-producao .fc-daygrid-event {
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
    margin: 2px 3px;
    border-radius: 6px;
    padding: 3px 6px;
    border: none !important;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.25);
}
#obra-calendario-producao .fc-daygrid-more-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: #2563eb;
}
#obra-calendario-producao .fc-scrollgrid {
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}
#obra-calendario-producao .fc-list {
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}
#obra-calendario-producao .fc-list-day-cushion {
    background: #f1f5f9 !important;
    font-weight: 700;
    font-size: 0.85rem;
    color: #334155;
    padding: 10px 12px !important;
}
#obra-calendario-producao .fc-list-event {
    cursor: default;
}
#obra-calendario-producao .fc-list-event-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}
#obra-calendario-producao .fc-list-event-time {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2563eb;
    white-space: nowrap;
}
#obra-calendario-producao .fc-list-event-dot {
    border-color: #2563eb !important;
}
.obra-agenda-producao__bottom {
    display: grid;
    grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}
@media (max-width: 768px) {
    .obra-agenda-producao__bottom {
        grid-template-columns: 1fr;
    }
    .obra-agenda-producao__head-actions {
        flex-direction: row;
        align-items: center;
        width: 100%;
        justify-content: space-between;
    }
    #obra-calendario-producao .fc-button {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 14px !important;
    }
    #obra-calendario-producao .fc-toolbar-title {
        font-size: 0.95rem !important;
        width: 100%;
        text-align: center;
        margin: 4px 0;
    }
    #obra-calendario-producao .fc-toolbar {
        justify-content: center;
    }
}
.obra-agenda-producao__panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px;
}
.obra-agenda-producao__panel-title {
    margin: 0 0 12px;
    font-size: 0.88rem;
    font-weight: 700;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 8px;
}
.obra-agenda-producao__panel-title i {
    color: #2563eb;
}
.obra-agenda-producao__form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
}
.obra-agenda-producao__form label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #475569;
    margin: 0 0 4px;
    grid-column: span 2;
}
.obra-agenda-producao__form label.obra-agenda-label--half { grid-column: span 1; }
.obra-agenda-producao__form input,
.obra-agenda-producao__form select {
    margin: 0;
    padding: 11px 12px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}
.obra-agenda-producao__form .obra-agenda-field--half { grid-column: span 1; }
.obra-agenda-producao__form .obra-agenda-field--full { grid-column: span 2; }
.obra-agenda-producao__submit {
    grid-column: span 2;
    margin: 6px 0 0;
    padding: 12px 16px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
    background: #2563eb !important;
    width: 100%;
    min-height: 48px;
}
.obra-agenda-producao__panel--list .obra-agenda-producao__lista {
    max-height: 320px;
}
.obra-agenda-producao__lista {
    max-height: 280px;
    overflow-y: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}
.obra-agenda-producao__empty {
    margin: 0;
    padding: 20px 12px;
    text-align: center;
    font-size: 0.88rem;
    color: #94a3b8;
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
}
.obra-agenda-producao__item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
    margin-bottom: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.88rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.obra-agenda-producao__item:last-child { margin-bottom: 0; }
.obra-agenda-producao__item.is-past { opacity: 0.72; }
.obra-agenda-producao__item.is-next {
    border-color: #93c5fd;
    box-shadow: 0 0 0 1px #bfdbfe;
}
.obra-agenda-producao__data {
    flex-shrink: 0;
    min-width: 52px;
    text-align: center;
    padding: 8px 10px;
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: #fff;
    border-radius: 10px;
    line-height: 1.15;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.obra-agenda-producao__item.is-past .obra-agenda-producao__data {
    background: #94a3b8;
    box-shadow: none;
}
.obra-agenda-producao__data b {
    display: block;
    font-size: 1.15rem;
    font-weight: 700;
}
.obra-agenda-producao__data small {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.obra-agenda-producao__meta { flex: 1; min-width: 0; }
.obra-agenda-producao__meta strong {
    display: block;
    color: #0f172a;
    font-size: 0.92rem;
    margin-bottom: 2px;
    word-break: break-word;
}
.obra-agenda-producao__meta span {
    color: #64748b;
    font-size: 0.8rem;
    line-height: 1.35;
}

/* Banner instalar PWA (só telemóvel — Android / iOS) */
.crm-pwa-install {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10050;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}
@media (min-width: 769px) {
    .crm-pwa-install { display: none !important; }
}
.crm-pwa-install__card {
    pointer-events: auto;
    max-width: 420px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    background: #1f2937;
    color: #f8fafc;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.35);
    position: relative;
}
.crm-pwa-install__close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.crm-pwa-install__icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}
.crm-pwa-install__icon-glyph {
    font-size: 1.15rem;
    line-height: 1;
    color: #fff;
}
.crm-pwa-install__body { flex: 1; min-width: 0; padding-right: 18px; }
.crm-pwa-install__title { display: block; font-size: 0.92rem; margin-bottom: 4px; }
.crm-pwa-install__text {
    margin: 0 0 10px;
    font-size: 0.78rem;
    line-height: 1.4;
    color: #cbd5e1;
}
.crm-pwa-install__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.crm-pwa-install__btn {
    background: #2563eb !important;
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
}
.crm-pwa-install__btn-secondary {
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
}
.crm-pwa-install__hint {
    margin: 8px 0 0;
    font-size: 0.72rem;
    color: #94a3b8;
    line-height: 1.35;
}

@keyframes fadeEffect { from {opacity: 0;} to {opacity: 1;} }

/* Drag & Drop */
.dd-container { 
    display: flex; 
    gap: 25px; 
}

.dd-sidebar { 
    width: 300px; 
    background: var(--bg-card); 
    padding: 20px; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    border: 1px solid #e5e7eb; 
    flex-shrink: 0;
}

.dd-main { 
    flex: 1; 
    background: var(--bg-card); 
    padding: 20px; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    border: 1px solid #e5e7eb; 
    min-width: 0;
}

.dd-container.crm-agenda-layout {
    align-items: flex-start;
    gap: 12px;
}
.dd-sidebar.crm-agenda-teams {
    width: 148px;
    padding: 12px 10px;
    position: sticky;
    top: calc(var(--header-height, 70px) + 12px);
    max-height: calc(100vh - var(--header-height, 70px) - 24px);
    overflow-y: auto;
    z-index: 4;
    -webkit-overflow-scrolling: touch;
}
.dd-container.crm-agenda-layout .dd-main {
    padding: 12px;
}
.dd-sidebar.crm-agenda-teams h3 {
    font-size: 0.92rem;
    margin: 0 0 8px;
}
.dd-sidebar.crm-agenda-teams .team-box {
    padding: 10px 8px;
    font-size: 0.82rem;
    line-height: 1.25;
}
.dd-sidebar.crm-agenda-teams p,
.dd-sidebar.crm-agenda-teams small {
    font-size: 0.75rem;
    line-height: 1.3;
}
.team-box.is-selected {
    outline: 2px solid #0284c7;
    background: #e0f2fe;
    border-color: #7dd3fc;
}
.crm-agenda-calendar .fc-daygrid-day {
    cursor: pointer;
}
body.crm-agenda-dragging {
    cursor: grabbing !important;
}
body.crm-agenda-dragging .crm-agenda-calendar-wrap {
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.35);
}

.team-box { 
    background: #f9fafb; 
    border: 1px solid #e5e7eb; 
    margin-bottom: 10px; 
    padding: 12px 14px; 
    border-radius: 12px; 
    cursor: move; 
    font-weight: 500;
    font-size: 0.88rem;
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    height: auto;
}

.team-box:hover { 
    border-color: var(--primary); 
    background: #eff6ff; 
}

/* Modal - Responsive */
.modal { 
    display:none; 
    position:fixed; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
    background:rgba(0,0,0,0.55); 
    z-index: var(--z-crm-modal, 1300);
    /* Sem backdrop-filter: em vários browsers causa ecrã "embaciado"/congelado com overlays */
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

html.crm-modal-open .modal.is-open,
html.crm-modal-open .modal[style*="display: block"],
body.crm-modal-open .modal:not([style*="display: none"]) {
    z-index: var(--z-crm-modal, 1300);
}

.modal-content { 
    background:#fff; 
    width:100%; 
    max-width: 700px;
    margin: 5% auto; 
    padding: 30px; 
    border-radius: var(--radius); 
    max-height: 90vh; 
    overflow-y: auto; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); 
    border: none; 
}
/* Modais curtos (ex.: nova obra): sem scroll interno, tamanho confortável */
.modal.modal--centered {
    align-items: center;
    justify-content: center;
}
.modal-content.modal-content--fit {
    max-height: none;
    overflow: visible;
    margin: 0;
    width: min(920px, calc(100vw - 40px));
    max-width: 920px;
}
#modalNovaObra .modal-content {
    max-height: none;
    overflow: visible;
    margin: 0;
    width: min(920px, calc(100vw - 40px));
    max-width: 920px;
}

.modal-nova-obra-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.modal-nova-obra-label-opt {
    font-weight: 400;
    color: #64748b;
}

.modal-nova-obra-nota {
    margin: 14px 0 0;
    font-size: 13px;
    color: #6b7280;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    line-height: 1.4;
}

.modal-nova-obra-acoes {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.modal-nova-obra-btn-cancel {
    background: #ccc;
}

/* Pesquisa live + sugestões de nomes */
.crm-live-filter-wrap {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 480px;
}
.crm-live-filter-wrap input[type="search"],
.crm-live-filter-wrap input[type="text"] {
    width: 100%;
    box-sizing: border-box;
}
.crm-live-filter-suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 1200;
    max-height: min(280px, 45vh);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}
.crm-live-filter-suggest__opt {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    color: #0f172a;
    font-family: inherit;
    border-bottom: 1px solid #f1f5f9;
}
.crm-live-filter-suggest__opt:last-child {
    border-bottom: none;
}
.crm-live-filter-suggest__opt:hover,
.crm-live-filter-suggest__opt.is-active {
    background: #e0f2fe;
    color: #0c4a6e;
}
.crm-live-filter-suggest__empty {
    padding: 12px;
    font-size: 0.88rem;
    color: #64748b;
}
tr.crm-live-filter-hit,
.obra-mobile-card.crm-live-filter-hit {
    outline: 3px solid #0369a1;
    outline-offset: -2px;
    background: #bae6fd !important;
    box-shadow: inset 4px 0 0 #0284c7;
}
tr.crm-live-filter-hit td {
    background: #bae6fd !important;
    font-weight: 600;
}
/* Esconder linhas do filtro — tem de ganhar a display:table-row !important do responsive */
.crm-live-filter-hidden,
tr.crm-live-filter-hidden,
.cliente-row.crm-live-filter-hidden,
.obra-row.crm-live-filter-hidden,
.obra-mobile-card.crm-live-filter-hidden,
.crm-list-responsive tbody tr.crm-live-filter-hidden,
.clientes-page.crm-list-responsive tbody tr.crm-live-filter-hidden,
.clientes-page.crm-list-responsive tbody tr.cliente-row.crm-live-filter-hidden {
    display: none !important;
}

/* Select pesquisável (ex.: cliente no modal Nova Obra) */
.crm-select-search {
    position: relative;
}
.crm-select-search__native {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    margin: 0;
    padding: 0;
    border: 0;
}
.crm-select-search__box {
    position: relative;
}
.crm-select-search__input {
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}
.crm-select-search__list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    z-index: 1100;
    max-height: min(220px, 40vh);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}
.crm-select-search__option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.88rem;
    color: #1e293b;
    font-family: inherit;
}
.crm-select-search__option:hover,
.crm-select-search__option.is-selected {
    background: #eff6ff;
}
.crm-select-search__empty {
    padding: 10px 12px;
    font-size: 0.85rem;
    color: #64748b;
}
.modal-content.has-win-chrome {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.win-modal-chrome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
    padding: 0 0 0 12px;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    border-bottom: 1px solid #cbd5e1;
    border-radius: var(--radius) var(--radius) 0 0;
    flex-shrink: 0;
    user-select: none;
}
.win-modal-chrome__title {
    flex: 1;
    min-width: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.win-modal-chrome__controls {
    display: flex;
    flex-shrink: 0;
    margin-left: auto;
}
.win-modal-btn {
    width: 44px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #334155;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.win-modal-btn:hover {
    background: rgba(15, 23, 42, 0.08);
}
.win-modal-btn--close:hover {
    background: #dc2626;
    color: #fff;
}
.win-modal-body {
    padding: 16px 20px 20px;
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}
.win-modal-title-in-chrome {
    display: none !important;
}
.modal-content.has-win-chrome.is-minimized {
    max-height: none !important;
    height: auto !important;
}
.modal-content.has-win-chrome.is-minimized .win-modal-body {
    display: none;
}
.modal-content.has-win-chrome.is-maximized {
    width: calc(100vw - 20px) !important;
    max-width: none !important;
    height: calc(100vh - 20px) !important;
    max-height: none !important;
    margin: 10px auto !important;
}
.obra-modal-agenda-producao__content.has-win-chrome .obra-modal-agenda-producao__inner {
    padding-top: 8px;
}

.dd-list { 
    border:1px solid #e5e7eb; 
    min-height:260px; 
    max-height:360px;
    overflow-y:auto;
    padding:10px; 
    background:#f9fafb; 
    border-radius: 12px;
    box-sizing: border-box;
}

.dd-item { 
    background:#dbeafe; 
    padding:8px; 
    margin:4px; 
    cursor:grab; 
    border-radius: 8px; 
    color: #1e40af; 
    font-weight: 500; 
}

.col-half { 
    width:48%; 
    display:inline-block; 
    vertical-align:top; 
}

/* Ticket Extras */
.priority-badge { 
    padding: 2px 8px; 
    border-radius: 10px; 
    font-size: 0.75rem; 
    font-weight: bold; 
    color: white; 
    display: inline-block; 
    white-space: nowrap;
}

.p-Baixa { background-color: #95a5a6; } 
.p-Normal { background-color: #3498db; } 
.p-Alta { background-color: #e67e22; } 
.p-Urgente { background-color: #e74c3c; }

.comment-thread { 
    background: #f8f9fa; 
    padding: 10px; 
    margin-top: 10px; 
    border-radius: 5px; 
    display: none; 
    border-top: 2px solid #ddd; 
}

.comment { 
    background: #fff; 
    padding: 8px; 
    margin-bottom: 8px; 
    border-radius: 4px; 
    border-left: 3px solid #bdc3c7; 
    font-size: 0.9rem; 
}

.comment-meta { 
    font-size: 0.75rem; 
    color: #7f8c8d; 
    margin-bottom: 3px; 
}

.btn-toggle { 
    background: none; 
    border: none; 
    color: #3498db; 
    cursor: pointer; 
    padding: 0; 
    font-size: 0.85rem; 
    text-decoration: underline; 
}

/* App Mobile Style */
.app-header { 
    background: var(--bg-card); 
    color: var(--text-main); 
    padding: 25px; 
    border-radius: 0 0 30px 30px; 
    margin-bottom: 25px; 
    box-shadow: var(--shadow); 
    text-align: center; 
}

.app-header h2 { 
    color: var(--primary); 
    margin-bottom: 5px; 
}

.app-card { 
    border-left: 5px solid var(--primary); 
}

.app-card h4 { 
    margin-top: 0; 
    color: var(--text-main); 
    font-size: 1.1rem; 
}

.app-label { 
    font-size: 0.7rem; 
    font-weight: 700; 
    color: var(--text-muted); 
    text-transform: uppercase; 
    letter-spacing: 1px; 
}

.app-value { 
    font-size: 1.25rem; 
    font-weight: 800; 
    color: var(--text-main); 
    margin-bottom: 10px; 
}

.alert-popup { 
    position: fixed; 
    top: 20px; 
    right: 20px; 
    background: #e74c3c; 
    color: white; 
    padding: 15px; 
    border-radius: 5px; 
    box-shadow: 0 0 10px rgba(0,0,0,0.2); 
    z-index: 9999; 
    display: none; 
    max-width: 90%;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-20 { margin-bottom: 20px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.w-full { width: 100%; }

/* Responsive Flex Helpers */
@media (max-width: 768px) {
    .flex-mobile-col { flex-direction: column !important; }
    .flex-mobile-wrap { flex-wrap: wrap !important; }
    .justify-mobile-between { justify-content: space-between !important; }
    .gap-mobile-10 { gap: 10px !important; }
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.page-header h2 {
    margin: 0;
}

.page-header .actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar input {
    margin: 0;
    flex: 1;
    min-width: 200px;
}

/* Form Grid */
.form-grid {
    display: grid;
    gap: 20px;
}

.form-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.form-row > div {
    flex: 1;
    min-width: 200px;
}

/* ================================================
   MEDIA QUERIES - RESPONSIVE DESIGN
   ================================================ */

/* Tablet Portrait — não alterar grids do dashboard em desktop */
@media (max-width: 1024px) {
    .container {
        padding: 15px;
        margin-top: 20px;
    }
    
    .chart-row {
        grid-template-columns: 1fr;
    }
    
    .dd-container {
        flex-direction: column;
    }
    
    .dd-sidebar {
        width: 100%;
    }
    
    .modal-content {
        margin: 10% auto;
        padding: 20px;
    }
}

/* Mobile Landscape */
@media (max-width: 768px) {
    /* CRM dual view mobile */
    .crm-desktop-only { display: none !important; }
    .crm-mobile-only { display: block !important; }
    .obra-mobile-list.crm-mobile-only { display: flex !important; flex-direction: column; gap: 12px; }

    :root {
        --radius: 16px;
    }
    
    html, body {
        overflow-x: hidden;
        max-width: 100%;
    }

    body {
        font-size: 14px;
    }

    /* Header Mobile — overflow-y visible para o painel do sininho (position:fixed) */
    header {
        padding: 0.5rem 0;
        overflow-x: clip;
        overflow-y: visible;
    }
    
    header nav.crm-topnav {
        padding: 0 10px;
    }
    
    header .logo-container img {
        height: 32px;
    }

    .crm-topnav__brand {
        flex: 1 1 auto;
        min-width: 0;
    }

    .crm-topnav__tools {
        margin-left: auto;
    }

    .menu-toggle {
        display: block !important;
    }
    
    /* Container */
    .container {
        width: 100%;
        max-width: 100%;
        padding: 10px;
        margin-top: 10px;
        box-sizing: border-box;
    }

    .card {
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .card .table-wrapper {
        overflow-x: visible;
        max-width: 100%;
    }

    .card .table-wrapper table {
        min-width: 0 !important;
        width: 100% !important;
    }
    
    /* Grids */
    .grid-3, .grid-2, .dashboard-grid, .chart-row,
    .dashboard-home .grid-2,
    .dashboard-home .grid-2.dashboard-split,
    .dashboard-home .grid-3 {
        grid-template-columns: 1fr;
    }
    
    .dashboard-grid {
        gap: 15px;
    }
    
    /* Cards */
    .card, .kpi-card, .chart-container, .app-card {
        padding: 15px;
    }
    
    h2 {
        font-size: 1.4rem;
    }
    
    h3 {
        font-size: 1.1rem;
    }
    
    /* Tables */
    table {
        font-size: 0.85rem;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    /* Buttons */
    .button {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
    
    .btn-small {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
    
    /* Forms */
    input, select, textarea {
        padding: 8px 10px;
        font-size: 0.9rem;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .col-half {
        width: 100%;
        display: block;
    }
    
    /* Page Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .page-header .actions {
        width: 100%;
    }
    
    .page-header .actions .button {
        flex: 1;
        justify-content: center;
    }
    
    /* Search Bar */
    .search-bar {
        flex-direction: column;
    }
    
    .search-bar input {
        width: 100%;
    }
    
    .search-bar .button {
        width: 100%;
        justify-content: center;
    }
    
    /* Modal — cabe na janela; sem overflow para a direita */
    .modal {
        padding: 8px;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    .modal-content,
    .modal .modal-content,
    .modal-content.has-win-chrome,
    .modal-content.has-win-chrome.is-maximized {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 15px;
        border-radius: 12px;
        box-sizing: border-box;
    }
    .modal-content.has-win-chrome {
        padding: 0;
    }
    .modal-content.has-win-chrome.is-maximized {
        height: auto !important;
        max-height: calc(100dvh - 16px) !important;
    }
    .modal .grid-2,
    .modal .grid-3 {
        grid-template-columns: 1fr !important;
        min-width: 0;
    }
    .app-card {
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    .app-card table {
        min-width: 0 !important;
        max-width: 100%;
    }

    /* Nova obra — compacto no telemóvel; botões sempre visíveis */
    #modalNovaObra.modal {
        padding: 8px 10px;
        align-items: center;
        justify-content: center;
    }

    #modalNovaObra .modal-content.modal-nova-obra {
        width: 100%;
        max-width: 100%;
        padding: 12px 14px 14px;
        margin: 0;
        max-height: calc(100dvh - 16px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    #modalNovaObra .modal-nova-obra h3 {
        margin: 0 0 8px;
        font-size: 1.05rem;
        flex-shrink: 0;
    }

    #modalNovaObra .modal-nova-obra-form {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1 1 auto;
    }

    #modalNovaObra .modal-nova-obra-form-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #modalNovaObra .modal-nova-obra-grid {
        grid-template-columns: 1fr !important;
        gap: 6px;
    }

    #modalNovaObra .modal-nova-obra-grid > div:last-child input {
        margin-bottom: 0;
    }

    #modalNovaObra label {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }

    #modalNovaObra input,
    #modalNovaObra select {
        padding: 7px 9px;
        margin: 0 0 6px;
        font-size: 0.88rem;
    }

    #modalNovaObra .modal-nova-obra-nota {
        margin: 8px 0 0;
        padding: 6px 8px;
        font-size: 0.72rem;
        line-height: 1.3;
    }

    #modalNovaObra .modal-nova-obra-acoes {
        flex-shrink: 0;
        gap: 8px;
        margin-top: 10px;
        padding-top: 2px;
    }

    #modalNovaObra .modal-nova-obra-acoes .button {
        flex: 1;
        margin: 0;
        padding: 8px 10px;
        font-size: 0.85rem;
        justify-content: center;
    }
    
    /* Tabs */
    .tab-bar {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    /* Ver obra: todos os separadores visíveis em várias linhas (sem scroll horizontal) */
    .ver-obra-page .tab-bar {
        overflow-x: visible;
        overflow-y: visible;
        flex-wrap: wrap;
        width: 100%;
        max-width: 100%;
    }

    .obra-tabs-fixed-inner .tab-btn {
        flex: 1 1 calc(50% - 3px);
        min-width: calc(50% - 3px);
        white-space: normal;
        text-align: center;
        line-height: 1.25;
        padding: 10px 8px;
    }
    
    .tab-btn {
        padding: 8px 15px;
        white-space: nowrap;
    }
    
    /* Drag & Drop */
    .dd-container {
        flex-direction: column;
    }
    
    .dd-sidebar, .dd-main {
        width: 100%;
    }
    
    /* App Header */
    .app-header {
        padding: 15px;
        border-radius: 0 0 20px 20px;
    }
    
    .app-header h2 {
        font-size: 1.3rem;
    }
    
    /* Status Badges */
    .status-badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
    
    /* Alerts */
    .alert-popup {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
    }

    /* Listagens: tabela em cartões */
    .table-cards-mobile .table-wrapper,
    .dashboard-home .table-wrapper {
        overflow-x: visible;
        margin-top: 0;
    }

    .table-cards-mobile table,
    .dashboard-home .table-wrapper table.dash-table {
        min-width: 0;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    .table-cards-mobile thead,
    .dashboard-home .table-wrapper table.dash-table thead {
        display: none;
    }

    .table-cards-mobile tbody,
    .dashboard-home .table-wrapper table.dash-table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .table-cards-mobile tr,
    .dashboard-home .table-wrapper table.dash-table tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-card);
        border-radius: 14px;
        box-shadow: var(--shadow);
        padding: 14px;
        border: 1px solid #e5e7eb;
    }

    .table-cards-mobile td.cell-obra-titulo,
    .dashboard-home .table-wrapper table.dash-table td.cell-obra-titulo {
        order: -1;
    }

    .table-cards-mobile tr:hover td,
    .dashboard-home .table-wrapper table.dash-table tr:hover td {
        background: transparent;
    }

    .table-cards-mobile td,
    .dashboard-home .table-wrapper table.dash-table td {
        display: block;
        padding: 7px 0;
        border-bottom: 1px solid #f1f5f9;
        text-align: left;
        word-break: break-word;
        overflow-wrap: break-word;
        line-height: 1.4;
    }

    .table-cards-mobile td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .table-cards-mobile td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        margin-bottom: 3px;
        line-height: 1.3;
    }

    .table-cards-mobile td:not([data-label])::before,
    .table-cards-mobile td[data-label=""]::before,
    .dashboard-home .table-wrapper table.dash-table td:not([data-label])::before,
    .dashboard-home .table-wrapper table.dash-table td[data-label=""]::before {
        content: none;
        display: none;
    }

    .table-cards-mobile td.cell-obra-titulo,
    .dashboard-home .table-wrapper table.dash-table td.cell-obra-titulo {
        order: -2;
        border-bottom: 1px solid #e2e8f0;
        padding: 0 0 10px;
        margin-bottom: 2px;
    }

    .table-cards-mobile td.cell-cliente-destaque {
        order: -1;
        font-weight: 600;
        color: #334155;
        padding-bottom: 10px;
        margin-bottom: 2px;
        border-bottom: 1px solid #f1f5f9;
    }

    .table-cards-mobile td.cell-obra-titulo::before,
    .table-cards-mobile td.cell-func-titulo::before,
    .dashboard-home .table-wrapper table.dash-table td.cell-func-titulo::before {
        margin-bottom: 5px;
    }

    .table-cards-mobile .obra-nome-text,
    .table-cards-mobile td.cell-func-titulo,
    .dashboard-home .table-wrapper table.dash-table td.cell-func-titulo {
        font-size: 1.02rem;
        font-weight: 700;
        color: #0f172a;
    }

    .table-cards-mobile td.cell-acoes {
        padding-top: 10px;
        margin-top: 4px;
        border-top: 1px dashed #e2e8f0;
        border-bottom: none;
    }

    .table-cards-mobile td.cell-acoes::before {
        margin-bottom: 8px;
    }

    .table-cards-mobile td.cell-acoes .obra-acoes-grid {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .table-cards-mobile td.cell-acoes .button {
        width: 100%;
        margin: 0;
        box-sizing: border-box;
        justify-content: center;
        padding: 11px 12px;
        font-size: 0.85rem;
    }

    .table-cards-mobile td.cell-stack-full,
    .dashboard-home .table-wrapper table.dash-table td.cell-stack-full {
        border: none;
        padding: 0;
    }

    .table-cards-mobile td.cell-stack-full::before,
    .dashboard-home .table-wrapper table.dash-table td.cell-stack-full::before {
        display: none;
    }

    .table-cards-mobile .dash-ticket-link,
    .dashboard-home .dash-ticket-link {
        display: block;
        line-height: 1.45;
    }

    .table-cards-mobile .dash-ticket-link .priority-badge,
    .dashboard-home .dash-ticket-link .priority-badge {
        margin-right: 6px;
        vertical-align: middle;
    }

    .obras-search-card {
        max-width: none !important;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    :root {
        --radius: 12px;
    }
    
    body {
        font-size: 13px;
    }
    
    .container {
        padding: 8px;
    }
    
    .card, .kpi-card, .chart-container, .app-card {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    h2 {
        font-size: 1.2rem;
    }
    
    header h1 {
        font-size: 1rem;
    }
    
    header .logo-container img {
        height: 28px;
    }
    
    /* Table compact for small screens */
    table {
        font-size: 0.8rem;
    }
    
    th, td {
        padding: 8px 6px;
    }
    
    /* Action buttons */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }
    
    .action-buttons .button {
        width: 100%;
        justify-content: center;
    }
    
    /* Priority badges */
    .priority-badge {
        font-size: 0.65rem;
        padding: 2px 6px;
    }
}

/* Print Styles */
@media print {
    header, .button, .menu-toggle {
        display: none !important;
    }
    
    .container {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
    }
    
    .card, .kpi-card, table {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    body {
        background: white;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    header a, .button, .tab-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .menu-toggle {
        min-height: 44px;
        min-width: 44px;
    }
    
    input, select, textarea {
        min-height: 44px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
