/* public/css/style.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f4f2;
  --surface:   #ffffff;
  --border:    rgba(0,0,0,0.1);
  --border-md: rgba(0,0,0,0.18);
  --text:      #1a1a18;
  --text-muted:#6b6b67;
  --blue:      #185FA5;
  --blue-light:#E6F1FB;
  --green:     #0F6E56;
  --green-light:#E1F5EE;
  --red:       #A32D2D;
  --red-light: #FCEBEB;
  --amber:     #854F0B;
  --amber-light:#FAEEDA;
  --radius:    8px;
  --radius-lg: 12px;
}

body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); line-height: 1.6; }

.page { min-height: 100vh; }

/* ── LOGIN ─────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.login-logo { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 28px; color: var(--blue); }
.login-logo i { font-size: 24px; }
.login-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 360px; }
.login-card h2 { font-size: 18px; font-weight: 500; margin-bottom: 20px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--text-muted); text-align: center; line-height: 1.8; }

/* ── TOPBAR ────────────────────────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 0.5px solid var(--border); height: 54px; display: flex; align-items: center; padding: 0 20px; gap: 16px; position: sticky; top: 0; z-index: 100; }
.topbar-logo { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--blue); white-space: nowrap; }
.topbar-logo i { font-size: 20px; }
.tab-bar { display: flex; gap: 4px; flex: 1; }
.tab { padding: 6px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px; border: 0.5px solid transparent; color: var(--text-muted); transition: all 0.15s; background: none; }
.tab.active { background: var(--bg); border-color: var(--border); color: var(--text); font-weight: 500; }
.tab:hover:not(.active) { background: var(--bg); }
.user-pill { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; color: var(--text-muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-light); color: var(--blue); font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ── LAYOUT ────────────────────────────────────────────────────────── */
.section { min-height: calc(100vh - 54px); }
.content { max-width: 860px; margin: 0 auto; padding: 24px 20px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 17px; font-weight: 500; }
.section-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; }

/* ── FORMS ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.form-group input { width: 100%; padding: 8px 10px; border-radius: var(--radius); border: 0.5px solid var(--border-md); background: var(--surface); font-size: 13px; color: var(--text); font-family: inherit; transition: border-color 0.15s; }
.form-group input:focus { outline: none; border-color: var(--blue); }

/* ── BUTTONS ───────────────────────────────────────────────────────── */
.btn-primary { padding: 8px 18px; border-radius: var(--radius); border: none; background: var(--blue); color: #fff; font-size: 13px; cursor: pointer; font-family: inherit; font-weight: 500; transition: background 0.15s; }
.btn-primary:hover { background: #0C447C; }
.btn-primary.full { width: 100%; padding: 10px; }
.btn-outline { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); border: 0.5px solid var(--border-md); background: transparent; color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit; transition: background 0.15s; }
.btn-outline:hover { background: var(--bg); }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 18px; padding: 4px; border-radius: var(--radius); display: flex; align-items: center; }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-sm { font-size: 12px; padding: 4px 10px; border-radius: var(--radius); border: 0.5px solid var(--border-md); background: transparent; color: var(--text); cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 4px; transition: background 0.12s; white-space: nowrap; }
.btn-sm:hover { background: var(--bg); }
.btn-sm.danger { border-color: #E24B4A; color: var(--red); }
.btn-sm.danger:hover { background: var(--red-light); }
.btn-sm.success { border-color: #1D9E75; color: var(--green); }
.btn-sm.success:hover { background: var(--green-light); }

/* ── CARDS ─────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 14px; }

/* ── METRICS ───────────────────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric-card { background: var(--bg); border-radius: var(--radius); padding: 14px 16px; }
.metric-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.metric-value { font-size: 24px; font-weight: 500; }
.metric-value.green { color: var(--green); }
.metric-value.amber { color: var(--amber); }
.metric-value.blue  { color: var(--blue); }

/* ── CLIENT ROWS ───────────────────────────────────────────────────── */
.client-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 0.5px solid var(--border); }
.client-row:last-child { border-bottom: none; padding-bottom: 0; }
.client-avatar { width: 36px; height: 36px; border-radius: 50%; background: #EEEDFE; color: #3C3489; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.client-info { flex: 1; min-width: 0; }
.client-name { font-size: 13px; font-weight: 500; }
.client-sub { font-size: 12px; color: var(--text-muted); }
.client-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.client-devices { margin-top: 10px; padding: 10px 12px; background: var(--bg); border-radius: var(--radius); font-size: 12px; }
.client-device-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; border-bottom: 0.5px solid var(--border); }
.client-device-row:last-child { border-bottom: none; }

/* ── DEVICE CARDS ──────────────────────────────────────────────────── */
.device-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 14px; transition: border-color 0.15s; }
.device-card.suspended { opacity: 0.65; }
.device-icon { width: 46px; height: 46px; border-radius: var(--radius); background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.device-icon i { font-size: 22px; color: var(--blue); }
.device-info { flex: 1; min-width: 0; }
.device-name { font-size: 14px; font-weight: 500; }
.device-model { font-size: 11px; color: var(--text-muted); font-family: monospace; margin-top: 2px; }
.device-status { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.on       { background: #1D9E75; }
.dot.off      { background: #B4B2A9; }
.dot.suspended{ background: #EF9F27; }

/* ── TOGGLE ────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.toggle { position: relative; width: 42px; height: 24px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: #D3D1C7; border-radius: 999px; transition: background 0.2s; }
.toggle-track::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: transform 0.2s; }
.toggle input:checked + .toggle-track { background: #1D9E75; }
.toggle input:checked + .toggle-track::before { transform: translateX(18px); }
.toggle input:disabled + .toggle-track { cursor: not-allowed; opacity: 0.5; }
.toggle-label { font-size: 11px; color: var(--text-muted); }

/* ── BADGES ────────────────────────────────────────────────────────── */
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.badge.active    { background: var(--green-light); color: var(--green); }
.badge.suspended { background: var(--amber-light); color: var(--amber); }

/* ── ALERTS ────────────────────────────────────────────────────────── */
.alert { border-radius: var(--radius); padding: 10px 14px; font-size: 13px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.alert-danger  { background: var(--red-light);   color: var(--red);   }
.alert-warning { background: var(--amber-light);  color: var(--amber); }

/* ── MODAIS ────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: var(--surface); border-radius: var(--radius-lg); border: 0.5px solid var(--border); padding: 22px; width: 340px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title { font-size: 15px; font-weight: 500; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── MISC ──────────────────────────────────────────────────────────── */
.loading { padding: 32px; text-align: center; color: var(--text-muted); font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.empty { padding: 40px; text-align: center; color: var(--text-muted); font-size: 13px; }
.empty i { font-size: 32px; display: block; margin-bottom: 10px; opacity: 0.4; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 0.9s linear infinite; }

/* ── Licença badges ─────────────────────────────────────────────────────── */
.client-lic { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.badge-info  { font-size: 11px; padding: 2px 8px; border-radius: 999px;
               background: #E6F1FB; color: #0C447C; font-weight: 500; }
.count-badge { display: inline-flex; align-items: center; justify-content: center;
               width: 17px; height: 17px; border-radius: 50%; background: #185FA5;
               color: #fff; font-size: 10px; font-weight: 600; margin-left: 2px; }
.divider-label { text-align: center; font-size: 12px; color: var(--text-muted);
                 margin: 8px 0; }

/* ── Rotinas modal ──────────────────────────────────────────────────────── */
.modal-lg { width: 560px; max-width: 96vw; }
.rotina-form { background: var(--bg); border-radius: var(--radius); padding: 14px; margin-bottom: 4px; }
.rotina-form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.rotina-form-row .form-group { flex: 1; min-width: 100px; }
.form-input-sm { width: 100%; padding: 7px 8px; border-radius: var(--radius);
                 border: 0.5px solid var(--border-md); background: var(--surface);
                 font-size: 13px; color: var(--text); font-family: inherit; }
.form-input-select { width: 100%; padding: 7px 8px; border-radius: var(--radius);
                     border: 0.5px solid var(--border-md); background: var(--surface);
                     font-size: 13px; color: var(--text); font-family: inherit; }

/* ── Rotinas table ──────────────────────────────────────────────────────── */
.rotinas-table { border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 4px; }
.rotinas-header { display: grid; grid-template-columns: 2fr 1fr 80px 50px 36px;
                  gap: 8px; padding: 8px 12px; background: var(--bg);
                  font-size: 11px; font-weight: 600; color: var(--text-muted);
                  text-transform: uppercase; letter-spacing: 0.05em; }
.rotina-row { display: grid; grid-template-columns: 2fr 1fr 80px 50px 36px;
              gap: 8px; padding: 10px 12px; font-size: 13px;
              border-top: 0.5px solid var(--border); align-items: center; }
.rotina-row:hover { background: var(--bg); }
.rotina-acao { font-weight: 500; font-size: 12px; }
.rotina-acao.ligar    { color: var(--green); }
.rotina-acao.desligar { color: var(--red); }
.rotina-hora { font-family: monospace; font-size: 14px; font-weight: 600; }
.toggle-sm { width: 34px; height: 19px; }
.toggle-sm .toggle-track::before { width: 13px; height: 13px; top: 3px; left: 3px; }
.toggle-sm input:checked + .toggle-track::before { transform: translateX(15px); }

/* ── btn-danger standalone ──────────────────────────────────────────────── */
.btn-danger { padding: 7px 14px; border-radius: var(--radius); border: 0.5px solid #E24B4A;
              background: transparent; color: var(--red); font-size: 13px; cursor: pointer;
              font-family: inherit; display: inline-flex; align-items: center; gap: 4px;
              transition: background 0.12s; }
.btn-danger:hover { background: var(--red-light); }

/* ── Tuya feedback (área do cliente) ──────────────────────────────────────── */
.tuya-feedback {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius);
  margin-top: 6px;
  font-weight: 500;
  transition: opacity 0.3s;
}
.tuya-loading {
  background: var(--bg);
  color: var(--text-muted);
  border: 0.5px solid var(--border);
}
.tuya-ok {
  background: var(--green-light);
  color: var(--green);
  border: 0.5px solid #A8E2D3;
}
.tuya-err {
  background: var(--red-light);
  color: var(--red);
  border: 0.5px solid #F5C0C0;
}

/* ── Tuya feedback inline (painel admin) ─────────────────────────────────── */
.tuya-feedback-inline {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}
.tuya-ok-inline  { background: var(--green-light); color: var(--green); }
.tuya-err-inline { background: var(--red-light);   color: var(--red);   max-width: 200px;
                   overflow: hidden; text-overflow: ellipsis; display: inline-block;
                   vertical-align: middle; }
