/* Portal IotMax — design system Cupertino */

:root {
  /* Cores */
  --color-primary: #007AFF;
  --color-primary-hover: #0066D6;
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-danger: #FF3B30;
  --color-info: #5856D6;

  --color-bg: #F2F2F7;
  --color-surface: #FFFFFF;
  --color-surface-2: #FAFAFC;
  --color-border: #E5E5EA;
  --color-border-subtle: #EFEFF4;

  --color-text: #1C1C1E;
  --color-text-secondary: rgba(60, 60, 67, 0.6);
  --color-text-tertiary: rgba(60, 60, 67, 0.3);

  /* Raios */
  --radius-card: 16px;
  --radius-button: 12px;
  --radius-input: 10px;
  --radius-pill: 9999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.05);

  /* Camada vidro */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-blur: saturate(180%) blur(20px);

  /* Tipografia */
  --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
}

/* Reset leve */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-stack);
  font-size: 17px;
  line-height: 1.4;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* Tipografia auxiliar */
.t-large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: -0.02em; }
.t-title-1 { font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: -0.01em; }
.t-title-2 { font-size: 22px; line-height: 28px; font-weight: 600; }
.t-title-3 { font-size: 20px; line-height: 25px; font-weight: 600; }
.t-headline { font-size: 17px; line-height: 22px; font-weight: 600; }
.t-body { font-size: 17px; line-height: 22px; font-weight: 400; }
.t-callout { font-size: 16px; line-height: 21px; font-weight: 400; }
.t-subhead { font-size: 15px; line-height: 20px; font-weight: 400; }
.t-footnote { font-size: 13px; line-height: 18px; font-weight: 400; }
.t-caption { font-size: 12px; line-height: 16px; font-weight: 400; letter-spacing: 0.01em; }
.t-secondary { color: var(--color-text-secondary); }
.t-tertiary { color: var(--color-text-tertiary); }

/* Layout app */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-primary) 0%, #5AC8FA 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.sidebar-section {
  margin-top: 16px;
  padding: 0 12px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--color-text);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s ease;
}
.nav-item:hover { background: var(--color-bg); text-decoration: none; }
.nav-item.is-active { background: rgba(0, 122, 255, 0.1); color: var(--color-primary); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Conteúdo */
.main { display: flex; flex-direction: column; min-width: 0; }
.content { padding: 32px; }
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.content-title { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-button);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  height: 40px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); text-decoration: none; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn-text { background: transparent; color: var(--color-primary); padding: 8px 12px; height: auto; }
.btn-text:hover { text-decoration: underline; background: transparent; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-icon {
  width: 40px;
  padding: 0;
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-icon:hover { background: var(--color-bg); }

/* Inputs */
.input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-input);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 15px;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input::placeholder { color: var(--color-text-tertiary); }
.input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.12); }
.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}
.field { margin-bottom: 16px; }

/* Card */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-subtle);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 17px; font-weight: 600; margin: 0; }
.card-subtitle { font-size: 13px; color: var(--color-text-secondary); margin: 2px 0 0; }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 20px;
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 8px;
}
.kpi-value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-delta {
  font-size: 13px;
  font-weight: 500;
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-danger); }
.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.kpi-icon.blue { background: rgba(0, 122, 255, 0.12); color: var(--color-primary); }
.kpi-icon.green { background: rgba(52, 199, 89, 0.12); color: var(--color-success); }
.kpi-icon.orange { background: rgba(255, 149, 0, 0.12); color: var(--color-warning); }
.kpi-icon.red { background: rgba(255, 59, 48, 0.12); color: var(--color-danger); }
.kpi-icon.indigo { background: rgba(88, 86, 214, 0.12); color: var(--color-info); }
.kpi-icon svg { width: 20px; height: 20px; }

/* Tabela */
.table-wrap {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--color-border-subtle);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; }
.table thead th {
  background: var(--color-surface-2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  text-align: left;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
}
.table tbody td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: 15px;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-surface-2); }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-online { background: rgba(52, 199, 89, 0.14); color: #1F8B3D; }
.badge-online .dot { background: var(--color-success); }
.badge-offline { background: rgba(60, 60, 67, 0.1); color: var(--color-text-secondary); }
.badge-offline .dot { background: var(--color-text-secondary); }
.badge-alarm { background: rgba(255, 59, 48, 0.12); color: var(--color-danger); }
.badge-alarm .dot { background: var(--color-danger); }
.badge-warn { background: rgba(255, 149, 0, 0.14); color: #B26800; }
.badge-warn .dot { background: var(--color-warning); }

/* Avatar */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5AC8FA, var(--color-primary));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

/* Search */
.search {
  position: relative;
  width: 320px;
}
.search input {
  height: 36px;
  padding-left: 36px;
  border-radius: 10px;
  background: var(--color-bg);
  border: 1px solid transparent;
}
.search input:focus { background: var(--color-surface); }
.search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-secondary);
}

/* Login */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #F2F2F7 0%, #E8EEFB 100%);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: 24px;
  padding: 40px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border-subtle);
}
.auth-logo {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--color-primary) 0%, #5AC8FA 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  margin: 0 auto 20px;
  box-shadow: var(--shadow-md);
}
.auth-title { text-align: center; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 6px; }
.auth-subtitle { text-align: center; font-size: 15px; color: var(--color-text-secondary); margin: 0 0 28px; }
.auth-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.auth-foot {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* Index navegacional */
.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.nav-card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 22px;
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--color-text);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.nav-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.nav-card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-card-icon svg { width: 22px; height: 22px; }
.nav-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nav-card-title { font-size: 15px; font-weight: 600; }
.nav-card-desc { font-size: 13px; color: var(--color-text-secondary); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(28, 28, 30, 0.4); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 24px; backdrop-filter: blur(4px); }
.modal-backdrop.is-open { display: flex; }
.modal { background: var(--color-surface); border-radius: 20px; max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); animation: modalin 0.2s ease; }
@keyframes modalin { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { padding: 24px 28px 16px; border-bottom: 1px solid var(--color-border-subtle); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 18px; font-weight: 600; margin: 0; }
.modal-close { background: transparent; border: 0; font-size: 22px; line-height: 1; color: var(--color-text-secondary); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--color-bg); }
.modal-body { padding: 20px 28px; }
.modal-foot { padding: 16px 28px 24px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--color-border-subtle); }

/* Action menu (kebab) */
.actions-cell { position: relative; }
.actions-btn { background: transparent; border: 0; width: 32px; height: 32px; border-radius: 8px; color: var(--color-text-secondary); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.actions-btn:hover { background: var(--color-bg); color: var(--color-text); }
.actions-menu { position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--color-surface); border: 1px solid var(--color-border-subtle); border-radius: 12px; box-shadow: var(--shadow-md); padding: 6px; min-width: 180px; display: none; z-index: 50; }
.actions-menu.is-open { display: block; }
.actions-menu button, .actions-menu a { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px; border: 0; background: transparent; font-size: 14px; color: var(--color-text); border-radius: 8px; cursor: pointer; text-align: left; text-decoration: none; }
.actions-menu button:hover, .actions-menu a:hover { background: var(--color-bg); }
.actions-menu .danger { color: var(--color-danger); }
.actions-menu .divider { height: 1px; background: var(--color-border-subtle); margin: 4px 0; }
.actions-menu form { margin: 0; }

/* Flash */
.flash { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--color-text); color: #fff; padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow-md); font-size: 14px; z-index: 200; animation: flashin 0.25s ease; }
@keyframes flashin { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* Form layout */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }
.input-error { border-color: var(--color-danger); }

/* Utilitários */
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.col-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1024px) {
  .col-2 { grid-template-columns: 1fr; }
}

/* Mini chart placeholder */
.spark {
  height: 60px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(0,122,255,0.12), rgba(0,122,255,0));
  position: relative;
  overflow: hidden;
}
.spark::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 18px;
  height: 2px;
  background: var(--color-primary);
  clip-path: polygon(0 80%, 10% 70%, 22% 75%, 35% 50%, 48% 60%, 60% 40%, 72% 55%, 84% 30%, 100% 35%, 100% 100%, 0 100%);
}

/* Chart placeholder */
.chart-placeholder {
  height: 240px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(0,122,255,0.08), rgba(0,122,255,0));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px;
  gap: 6px;
}
.chart-placeholder .bar {
  flex: 1;
  background: var(--color-primary);
  border-radius: 4px 4px 0 0;
  opacity: 0.85;
}
