:root {
  color-scheme: dark;
  --paper: #0a0b0c;
  --white: #111314;
  --ink: #ecece9;
  --muted: #858987;
  --line: #272a2b;
  --accent: #c6a06b;
  --accent-soft: #242019;
  --green: #a0ad9e;
  --red: #bd8077;
  --sans: "Montserrat", sans-serif;
  --serif: "Bebas Neue", Impact, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 13px; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

/* 1. Ecrã de Login e Registo (Supabase) */
.login-screen { 
  min-height: 100vh; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  background: var(--paper);
  background-image: radial-gradient(circle at top, var(--accent-soft), transparent 60%);
}

.login-card { 
  width: min(420px, calc(100% - 40px)); 
  padding: 48px 40px; 
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
}

.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); font: 500 16px var(--serif); text-decoration: none; }
.brand-mark-large { width: 52px; height: 52px; margin: 0 auto 24px; font-size: 20px; }
.login-card h1, .login-card .eyebrow, .login-description { text-align: center; }

.eyebrow { margin: 0 0 10px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }
.login-card h1 { margin: 0; font: 500 clamp(32px, 5vw, 42px)/1.12 var(--serif); letter-spacing: -.04em; color: var(--ink); }
.login-card h1 em, .tip-panel h3 em { color: var(--accent); font-weight: 500; }
.login-description { margin: 16px auto 30px; color: var(--muted); line-height: 1.6; max-width: 320px; }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 0 0 22px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.auth-tab { min-height: 38px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; transition: all 0.2s; }
.auth-tab.active { background: var(--white); color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,0.3); }

.login-form { display: grid; gap: 14px; width: 100%; }
.login-field { display: grid; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 600; }
.login-field input { width: 100%; min-height: 45px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 4px; outline: 0; background: var(--paper); color: var(--ink); font-size: 13px; }
.login-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(198, 160, 107, 0.15); }

.google-button { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 48px; border: 1px solid var(--accent); border-radius: 5px; background: var(--accent); color: var(--paper); font-weight: 600; cursor: pointer; transition: background .2s, transform .2s; margin-top: 8px; }
.google-button:hover { transform: translateY(-1px); background: #e1bd86; }
.google-button:disabled { cursor: wait; opacity: .55; transform: none; }

.setup-hint, .login-error { margin: 16px 0 0; padding: 13px; border: 1px solid #493b2b; border-radius: 4px; background: #211c15; color: #e1c49d; font-size: 11px; line-height: 1.7; text-align: left; }
.login-error a { display: inline-block; margin-top: 5px; color: #e7c28e; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.privacy-note { margin: 20px 0 0; color: var(--muted); font-size: 10px; text-align: center; }

.login-art { display: none; }

/* 2. Layout Principal (Sidebar e Área de Trabalho) */
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; z-index: 2; inset: 0 auto 0 0; display: flex; flex-direction: column; width: 238px; padding: 28px 18px 18px; overflow-y: auto; border-right: 1px solid var(--line); background: var(--white); scrollbar-width: thin; }
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px 40px; color: inherit; text-decoration: none; }
.brand-name { font-size: 11px; font-weight: 700; letter-spacing: .13em; color: var(--ink); }
.brand-name small { display: block; margin-top: 4px; color: var(--muted); font-size: 7px; letter-spacing: .13em; }
.sidebar-label, .sidebar-group-label { padding: 0 10px 12px; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .16em; }
.sidebar-group-label { margin: 28px 10px 10px; }
.main-nav, .secondary-nav { display: grid; gap: 5px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 11px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-link:hover, .nav-link.active { background: var(--accent-soft); color: var(--ink); }
.nav-link.active { font-weight: 700; box-shadow: inset 2px 0 var(--accent); }
.nav-icon { width: 18px; color: var(--accent); font-size: 16px; text-align: center; }
.nav-icon svg { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-bottom { margin-top: auto; }
.support-note { margin: 0 4px 17px; padding: 15px 14px 13px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); }
.note-icon { color: var(--accent); font-size: 16px; }
.support-note p { margin: 8px 0 0; color: var(--ink); font: 500 14px/1.45 var(--serif); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 13px 7px 0; border-top: 1px solid var(--line); }
.avatar { flex: none; width: 31px; height: 31px; border-radius: 50%; background: var(--line); object-fit: cover; }
.user-name { overflow: hidden; flex: 1; color: var(--ink); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { display: inline-grid; flex: none; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; }
.icon-button:hover { background: var(--line); color: var(--ink); }
.workspace { max-width: 1600px; min-height: 100vh; margin-left: 238px; padding: 0 clamp(28px, 5.2vw, 78px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 35px 0 26px; border-bottom: 1px solid var(--line); }
.topbar .eyebrow { margin-bottom: 6px; }
.topbar h1 { margin: 0; font: 500 30px var(--serif); letter-spacing: -.02em; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 22px; }
.sync-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.sync-status i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* 3. Botões e Componentes */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 38px; padding: 0 15px; border: 1px solid transparent; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer; transition: background .18s, transform .18s; }
.button:hover { transform: translateY(-1px); }
.button-dark { background: var(--accent); color: var(--paper); }
.button-dark:hover { background: #e1bd86; }
.button-dark span { font-size: 16px; font-weight: 400; }
.button-quiet { border-color: var(--line); background: var(--white); color: var(--ink); }
.button-danger { border: 0; background: transparent; color: var(--red); }
.text-button { padding: 5px 0; border: 0; background: none; color: var(--muted); font-size: 10px; cursor: pointer; }
.text-button:hover { color: var(--ink); }
.text-button span { margin-left: 5px; color: var(--accent); }

/* 4. Dashboard e Cards */
.view-section { padding: 30px 0 0; }
.welcome-row, .section-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 21px; }
.welcome-row h2, .section-intro h2 { margin: 0 0 5px; font: 500 24px var(--serif); letter-spacing: -.02em; color: var(--ink); }
.welcome-row p, .section-intro p { margin: 0; color: var(--muted); font-size: 11px; }
.wave { color: var(--accent); font: 20px var(--sans); }
.stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 13px; }
.stat-card { min-height: 118px; padding: 17px 18px 14px; border: 1px solid var(--line); border-radius: 5px; background: var(--white); }
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 10px; }
.stat-icon { color: var(--accent); font-size: 17px; }
.stat-card strong { display: block; margin: 8px 0 2px; font: 500 31px/1 var(--serif); color: var(--ink); }
.stat-card small { color: var(--muted); font-size: 9px; }
.panel { border: 1px solid var(--line); border-radius: 5px; background: var(--white); margin-top: 14px; padding: 19px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading h3 { margin: 0; font: 500 19px var(--serif); color: var(--ink); }

/* 5. Listas e Status */
.status-pill { flex: none; padding: 5px 7px; border-radius: 20px; background: var(--line); color: var(--muted); font-size: 8px; }
.status-pill.confirmado, .status-pill.pago { background: #1c2b23; color: #8ac49d; }
.status-pill.pendente, .status-pill.em-andamento { background: #2c271e; color: #d9bc83; }
.status-pill.cancelado { background: #33211f; color: #dd948b; }
.empty-state { padding: 22px 12px; color: var(--muted); font-size: 10px; line-height: 1.6; text-align: center; }

/* 6. Pesquisa */
.search-field { display: flex; align-items: center; gap: 7px; width: 100%; max-width: 300px; min-height: 35px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 10px; }
.search-field input::placeholder { color: var(--muted); }

/* 7. Dialogs (Modais de Edição) */
.record-dialog { width: min(520px, calc(100% - 28px)); max-height: min(88vh, 800px); padding: 0; overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; background: var(--white); color: var(--ink); box-shadow: 0 22px 70px rgba(0,0,0,0.5); }
.record-dialog::backdrop { background: rgba(5,6,6,0.8); backdrop-filter: blur(2px); }
.record-dialog form { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.dialog-heading h2 { margin: 0; font: 500 26px var(--serif); color: var(--ink); }
.form-fields { display: grid; gap: 13px; }
.form-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 600; }
.form-fields input, .form-fields select, .form-fields textarea { width: 100%; min-height: 38px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 4px; outline: 0; background: var(--paper); color: var(--ink); font-size: 11px; font-weight: 400; }
.form-fields input:focus, .form-fields select:focus, .form-fields textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(198,160,107,0.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.dialog-actions > span { flex: 1; }
.form-error { margin: 12px 0 0; color: var(--red); font-size: 10px; }

/* 8. Toast Notifications */
.toast { position: fixed; z-index: 5; right: 22px; bottom: 22px; max-width: min(380px, calc(100vw - 44px)); padding: 12px 16px; border-radius: 5px; background: var(--accent); color: var(--paper); font-size: 11px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }

/* 9. Elementos Específicos: Clientes, Agenda, Trabalhos */
.clients-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 18px; }
.client-card { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: inherit; cursor: pointer; transition: border-color .2s; }
.client-card:hover { border-color: var(--accent); }
.client-card .client-initial { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: bold; }
.client-card-content { overflow: hidden; flex: 1; }
.client-card-content strong { display: block; font-size: 11px; color: var(--ink); }
.client-card-content small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }

.workflow-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 11px 12px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; cursor: pointer; transition: background .18s; }
.workflow-row:hover { background: var(--line); }
.workflow-row-main { display: flex; flex: 1; flex-direction: column; gap: 5px; }
.workflow-row-main strong { color: var(--ink); font-size: 11px; font-weight: 600; }
.workflow-row-main small { color: var(--muted); font-size: 9px; }
.workflow-amount { flex: none; color: var(--ink); font-size: 10px; font-weight: 600; }
.workflow-amount.positive { color: var(--green); }
.workflow-amount.negative { color: var(--red); }

/* Calendário */
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.calendar-weekdays { background: var(--paper); color: var(--muted); font-size: 9px; text-align: center; }
.calendar-weekdays span { padding: 8px 5px; }
.calendar-day { display: block; min-height: 100px; padding: 7px; background: var(--white); color: var(--ink); }
.calendar-day.outside { color: var(--muted); opacity: 0.5; }
.calendar-day:hover { background: var(--paper); }
.calendar-date { display: flex; align-items: center; width: 100%; background: transparent; border: none; color: inherit; font-size: 16px; font-weight: bold; cursor: pointer; }
.calendar-event { display: block; width: 100%; padding: 4px 5px; margin-top: 4px; border-left: 2px solid var(--accent); background: var(--paper); color: var(--ink); font-size: 9px; text-align: left; cursor: pointer; }

/* 10. Responsividade (Mobile) */
@media (max-width: 760px) {
  .login-card { padding: 30px 20px; width: calc(100% - 32px); margin: 0 16px; }
  
  .sidebar { position: fixed; inset: auto 0 0; z-index: 10; display: flex; flex-direction: row; width: 100%; height: calc(62px + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom); border: 0; border-top: 1px solid var(--line); background: var(--white); }
  .sidebar > .brand, .sidebar > .sidebar-label, .sidebar > .sidebar-bottom, .sidebar-group-label { display: none; }
  .main-nav { display: flex; flex: 1; gap: 2px; width: 100%; justify-content: space-around; }
  .nav-link { flex-direction: column; justify-content: center; gap: 3px; font-size: 8px; padding: 5px; }
  .nav-link.active { box-shadow: inset 0 -2px var(--accent); }
  
  .workspace { margin: 0; padding: 0 16px calc(80px + env(safe-area-inset-bottom)); }
  .topbar { display: none; }
  
  .stat-grid { grid-template-columns: 1fr; }
  .clients-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  
  .record-dialog { width: calc(100% - 24px); max-height: calc(100dvh - 40px); margin: auto; }
}