/* ============================================================
   Reset & Base
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface2:     #1c2128;
  --border:       #30363d;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --primary:      #388bfd;
  --primary-dim:  #1f4b8e;
  --green:        #3fb950;
  --yellow:       #d29922;
  --red:          #f85149;
  --radius:       6px;
  --font-mono:    'Courier New', Courier, monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================
   Utilities
============================================================ */
.hidden { display: none !important; }

.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-red   { background: var(--red); }

/* ============================================================
   Buttons
============================================================ */
.btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover       { background: var(--surface2); }
.btn-primary     { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1a6fda; border-color: #1a6fda; }
.btn-ghost       { border-color: transparent; }
.btn-danger      { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: rgba(248,81,73,.1); }
.btn-sm { padding: 3px 10px; font-size: 12px; }

/* ============================================================
   Screens
============================================================ */
.screen { min-height: 100vh; }

/* ============================================================
   Login
============================================================ */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-logo {
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 4px;
  text-align: center;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: -8px;
}

.login-error {
  background: rgba(248,81,73,.1);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--red);
  font-size: 13px;
}

.login-box input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.login-box input:focus { border-color: var(--primary); }

.login-box .btn-primary {
  width: 100%;
  padding: 10px;
  font-size: 15px;
}

.login-ws-status {
  display: flex;
  align-items: center;
  gap: 7px;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* ============================================================
   Header
============================================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  color: var(--text-muted);
  font-size: 13px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
  justify-content: flex-end;
}
.header-user { color: var(--text-muted); font-size: 13px; }

/* ============================================================
   Tabs
============================================================ */
.tabs {
  display: flex;
  gap: 2px;
}

.tab {
  padding: 6px 18px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  transition: color .15s, border-color .15s;
}
.tab:hover  { color: var(--text); }
.tab.active {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface2);
}

/* ============================================================
   Main / Tab content
============================================================ */
.main { padding: 24px; }

.tab-content { }

.tab-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.tab-toolbar h2 { font-size: 18px; font-weight: 600; }

/* ============================================================
   Device list (My Devices & All Devices)
============================================================ */
.device-list { display: flex; flex-direction: column; gap: 0; }

.device-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  background: var(--surface);
  overflow: hidden;
}

.device-main {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 12px;
}

.dv-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  max-width: 200px;
  min-width: 0;
}

.device-name    { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-id      { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.device-comment { flex: 1; min-width: 0; color: var(--text-muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-psk     { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.device-psk span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; cursor: pointer; }

.dv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  min-width: 100px;
}

.last-signal {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.device-uptime {
  font-size: 12px;
  color: var(--green);
  white-space: nowrap;
}

.dv-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ============================================================
   Module panel
============================================================ */
.device-modules {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.modules-empty {
  font-size: 12px;
  color: var(--text-muted);
}

.module-btn {
  padding: 4px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.module-btn:hover { opacity: .8; }
.module-on  { background: var(--green);   color: #000; border-color: var(--green); }
.module-off { background: var(--surface); color: var(--text-muted); }

/* ============================================================
   Device Log
============================================================ */
.device-log {
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.device-log-entries {
  height: 180px;
  overflow-y: auto;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.log-entry {
  display: flex;
  gap: 10px;
  line-height: 1.4;
}
.log-time { color: var(--text-muted); flex-shrink: 0; }
.log-type { color: var(--primary); flex-shrink: 0; width: 60px; }
.log-data { color: var(--green); word-break: break-all; }

.device-command {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-command select {
  padding: 5px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.device-command input {
  flex: 1;
  padding: 5px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
}
.device-command input:focus { border-color: var(--primary); }
.cmd-key-input { flex: 0 0 120px; }

/* ============================================================
   Users list
============================================================ */
.users-list { display: flex; flex-direction: column; gap: 6px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.user-login    { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role     { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.role-admin    { color: var(--yellow); }
.user-devcount { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.user-actions  { display: flex; gap: 6px; flex-shrink: 0; }

/* ============================================================
   Modal
============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 420px;
  max-width: 95vw;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: var(--radius);
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-body input,
.modal-body select,
.modal-body textarea {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.modal-body input:focus,
.modal-body textarea:focus { border-color: var(--primary); }
.modal-body textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); font-size: 12px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Confirm dialog (danger)
============================================================ */
.confirm-text {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}
.confirm-text strong { color: var(--text); }

/* ============================================================
   Empty state
============================================================ */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ============================================================
   Responsive — Mobile (≤640px)
============================================================ */
@media (max-width: 640px) {

  .main { padding: 12px; }

  /* Header: ws-статус + ім'я/вихід | вкладки під ними */
  .header {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
  }
  .header-left { order: 1; flex: 1; min-width: 0; }
  .header-right { order: 2; }
  .tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; font-size: 13px; padding: 5px 12px; }

  /* Device rows — картка */
  .device-main {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .dv-info   { flex: 1; max-width: none; }
  .dv-meta   { order: 3; margin-left: auto; align-items: flex-end; min-width: 0; }
  .device-comment { order: 4; width: 100%; white-space: normal; }
  .dv-actions     { order: 5; width: 100%; flex-wrap: wrap; }

  /* User rows */
  .user-row { flex-wrap: wrap; padding: 10px 12px; }
  .user-login    { order: 1; width: 100%; }
  .user-role     { order: 2; }
  .user-devcount { order: 3; margin-left: auto; }
  .user-actions  { order: 4; width: 100%; }

  /* Модулі */
  .device-modules { gap: 6px; padding: 8px 12px; }

  /* Команда */
  .device-command { flex-wrap: wrap; }
  .cmd-key-input  { flex: 0 0 100%; }
}
