:root {
  --green: #25d366;
  --green-dark: #128c7e;
  --green-darker: #075e54;
  --bg: #f0f2f5;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #667781;
  --border: #e9edef;
  --danger: #ea0038;
  --admin: #5b21b6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, var(--green-darker) 0%, var(--green-dark) 50%, var(--green) 100%); }
.auth-card { background: var(--card); border-radius: var(--radius); padding: 36px 32px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.brand { text-align: center; margin-bottom: 28px; }
.brand-icon { width: 56px; height: 56px; background: var(--green); color: #fff; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; margin-bottom: 12px; }
.brand-icon.admin { background: var(--admin); }
.brand-icon.sm { width: 32px; height: 32px; font-size: 11px; border-radius: 8px; display: inline-flex; vertical-align: middle; margin-right: 8px; }
.brand h1 { font-size: 22px; margin-bottom: 4px; }
.brand p { color: var(--muted); font-size: 14px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; }
.auth-footer a { color: var(--green-dark); text-decoration: none; font-weight: 500; }
.auth-footer.muted a { color: var(--muted); }

/* Forms */
.form label, .form-inline label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--muted); }
.form input, .form select, .form-inline input, .form-inline select, .filters input, .filters select {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; margin-bottom: 14px;
}
.form-inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-inline input, .form-inline select { width: auto; flex: 1; min-width: 140px; margin-bottom: 0; }
.form-sm input { min-width: 180px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 18px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; transition: opacity .15s; }
.btn:hover { opacity: .88; }
.btn-primary { background: var(--green); color: #fff; }
.btn-secondary { background: #e9edef; color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-admin { background: var(--admin); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* Topbar */
.topbar { background: var(--green-darker); color: #fff; padding: 0 24px; }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 56px; }
.topbar-brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar-user .btn-ghost { color: #fff; border-color: rgba(255,255,255,.3); }
.back-link { color: rgba(255,255,255,.8); text-decoration: none; font-size: 14px; margin-right: 12px; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
.panel { background: var(--card); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel h2 { font-size: 18px; margin-bottom: 16px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.panel-header h2 { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Status */
.status { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; text-transform: capitalize; }
.status-connected { background: #dcfce7; color: #166534; }
.status-qr { background: #fef9c3; color: #854d0e; }
.status-disconnected, .status-logged_out { background: #f3f4f6; color: #6b7280; }

/* Device grid */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.device-card { border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.device-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.device-card-header h3 { font-size: 16px; }
.device-card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.empty-state { text-align: center; padding: 40px; color: var(--muted); }

/* QR */
.qr-area { display: flex; align-items: center; justify-content: center; min-height: 280px; background: #fafafa; border-radius: 10px; border: 2px dashed var(--border); margin: 16px 0; }
.qr-area img { max-width: 260px; border-radius: 8px; }
.qr-loading { color: var(--muted); }
.connected-info { text-align: center; padding: 24px; background: #dcfce7; border-radius: 10px; margin: 16px 0; }
.hidden { display: none !important; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }
.dir-in { color: #2563eb; }
.dir-out { color: var(--green-dark); }

/* Admin */
.user-block { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.user-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.user-header strong { margin-right: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tag-admin { background: #ede9fe; color: var(--admin); }
.badge { background: var(--border); padding: 2px 10px; border-radius: 20px; font-size: 13px; font-weight: normal; }
.muted { color: var(--muted); font-size: 14px; }
.muted.sm { font-size: 12px; }
.muted.empty { padding: 12px 0; }
code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.api-key-full { display: block; word-break: break-all; padding: 10px; margin: 8px 0; background: #f9fafb; border-radius: 6px; font-size: 11px; }
.info-box { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }

/* Filters & pagination */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; margin-bottom: 0; min-width: 120px; }
.pagination { display: flex; gap: 8px; margin-top: 16px; justify-content: center; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--green); color: #fff; border-color: var(--green); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
