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

:root {
  --orange: #f47920;
  --orange-dark: #d4661a;
  --orange-light: #ffa040;
  --sidebar-bg: #1a1d23;
  --sidebar-border: #2d3139;
  --sidebar-text: #9ba3b0;
  --sidebar-hover: #252930;
  --sidebar-active: #2d3139;
  --content-bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 6px;
  --up-color: #22c55e;
  --down-color: #ef4444;
  --sidebar-w: 240px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 14px; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: width 0.2s;
}
#sidebar.collapsed { width: 0; overflow: hidden; }

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.logo { display: flex; align-items: baseline; gap: 0; line-height: 1; }
.logo-v { color: var(--orange); font-size: 28px; font-weight: 900; line-height: 1; }
.logo-text { color: #fff; font-size: 20px; font-weight: 600; }
.logo-sub { color: var(--sidebar-text); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; }

.nav-section { padding: 12px 0; border-bottom: 1px solid var(--sidebar-border); }
.nav-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: #4b5563; padding: 0 16px 6px; }

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #e5e7eb; }
.nav-item.active { background: var(--sidebar-active); color: #fff; border-left: 3px solid var(--orange); padding-left: 13px; }
.nav-icon { font-size: 10px; opacity: 0.6; }

/* ===== Filters ===== */
.filter-group { padding: 6px 16px; }
.filter-group label { display: block; font-size: 11px; color: #6b7280; margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.05em; }
.filter-group select {
  width: 100%; background: #252930; color: #e5e7eb;
  border: 1px solid var(--sidebar-border); border-radius: 4px;
  padding: 5px 8px; font-size: 12px; cursor: pointer;
}
.filter-group select:focus { outline: none; border-color: var(--orange); }

.btn-clear {
  margin: 8px 16px 0; display: block; width: calc(100% - 32px);
  background: transparent; color: #6b7280; border: 1px solid #374151;
  border-radius: 4px; padding: 5px; font-size: 11px; cursor: pointer;
  transition: all 0.15s;
}
.btn-clear:hover { background: #374151; color: #e5e7eb; }

.sidebar-footer { padding: 12px 16px; margin-top: auto; border-top: 1px solid var(--sidebar-border); }
.btn-import {
  width: 100%; background: #252930; color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border); border-radius: 4px; padding: 8px;
  font-size: 12px; cursor: pointer; transition: all 0.15s;
}
.btn-import:hover { background: var(--sidebar-hover); color: #e5e7eb; }

/* ===== Main Content ===== */
#content { flex: 1; display: flex; flex-direction: column; background: var(--content-bg); overflow: hidden; }

#view-devices { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* ===== Topbar ===== */
.topbar {
  background: var(--card-bg); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.search-wrap { position: relative; flex: 1; max-width: 600px; }
.search-wrap input {
  width: 100%; padding: 8px 12px 8px 36px;
  background: var(--content-bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-wrap input:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(244,121,32,0.15); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.result-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.btn-sidebar-toggle { background: none; border: none; font-size: 18px; color: var(--text-muted); cursor: pointer; padding: 4px 8px; }
.btn-sidebar-toggle:hover { color: var(--text); }

/* ===== Table ===== */
#results-container { flex: 1; overflow: auto; padding: 0; }

#results-table {
  width: 100%; border-collapse: collapse;
  background: var(--card-bg);
  font-size: 13px;
}
#results-table thead { position: sticky; top: 0; z-index: 10; }
#results-table th {
  background: #f9fafb; border-bottom: 2px solid var(--border);
  padding: 10px 12px; text-align: left; font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  white-space: nowrap;
}
#results-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
#results-table tbody tr { cursor: pointer; transition: background 0.1s; }
#results-table tbody tr:hover { background: #faf9f7; }

#results-table th[data-sort] { cursor: pointer; user-select: none; }
#results-table th[data-sort]:hover { color: var(--text); background: #f1f2f4; }
#results-table th.sort-asc::after  { content: ' ▲'; color: var(--orange); }
#results-table th.sort-desc::after { content: ' ▼'; color: var(--orange); }

.name-cell { font-family: 'SF Mono', 'Consolas', monospace; font-size: 12px; color: var(--text); max-width: 280px; word-break: break-all; }
.name-cell strong { color: var(--orange); }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-type-cpe      { background: #dbeafe; color: #1d4ed8; }
.badge-type-core     { background: #fce7f3; color: #9d174d; }
.badge-type-coref    { background: #fce7f3; color: #9d174d; }
.badge-type-coresw   { background: #fef3c7; color: #92400e; }
.badge-type-csw      { background: #fef3c7; color: #92400e; }
.badge-type-sw       { background: #f3f4f6; color: #374151; }
.badge-type-edge     { background: #ede9fe; color: #5b21b6; }
.badge-type-pop      { background: #d1fae5; color: #065f46; }
.badge-type-popsw    { background: #ccfbf1; color: #0f766e; }
.badge-type-anta     { background: #e0f2fe; color: #075985; }
.badge-type-antb     { background: #f0f9ff; color: #0c4a6e; }
.badge-type-sect     { background: #f0abfc; color: #6b21a8; }
.badge-type-cam      { background: #fee2e2; color: #991b1b; }
.badge-type-ups      { background: #fef9c3; color: #854d0e; }
.badge-type-pwr      { background: #fef9c3; color: #854d0e; }
.badge-type           { background: #f3f4f6; color: #374151; }

.badge-status-active     { background: #d1fae5; color: #065f46; }
.badge-status-vacant     { background: #f3f4f6; color: #6b7280; }
.badge-status-cancelled  { background: #fee2e2; color: #991b1b; }
.badge-status-paused     { background: #fef3c7; color: #92400e; }
.badge-status-suspended  { background: #fef3c7; color: #92400e; }
.badge-status            { background: #f3f4f6; color: #374151; }

.badge-up   { background: #d1fae5; color: #065f46; }
.badge-down { background: #fee2e2; color: #991b1b; }
.badge-fno  { background: #ede9fe; color: #5b21b6; }
.badge-backup { background: #fef3c7; color: #92400e; }

/* ===== Action buttons in table ===== */
.action-btn {
  display: inline-block; padding: 3px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-decoration: none; border: none; cursor: pointer;
  white-space: nowrap; transition: opacity 0.15s;
}
.action-btn:hover { opacity: 0.8; }
.btn-winbox { background: var(--orange); color: #fff; }
.btn-detail { background: #e5e7eb; color: var(--text); margin-left: 4px; }
.btn-copy-ip {
  background: #e5e7eb; color: var(--text); margin-left: 4px;
  font-family: 'SF Mono', 'Consolas', monospace; font-size: 11px;
}
.btn-copy-ip.btn-copied { background: #d1fae5; color: #065f46; }
.btn-copy-ip-inline {
  background: none; border: none; cursor: pointer; padding: 0 4px;
  color: var(--text-muted); font-size: 13px; vertical-align: middle;
  transition: color 0.15s;
}
.btn-copy-ip-inline:hover { color: var(--orange); }
.btn-copy-ip-inline.btn-copied { color: #22c55e; }

/* ===== Pagination ===== */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 16px; background: var(--card-bg); border-top: 1px solid var(--border); flex-shrink: 0; }
.page-btn { padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--card-bg); cursor: pointer; font-size: 13px; transition: all 0.15s; }
.page-btn:hover { background: var(--content-bg); }
.page-btn.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 12px; color: var(--text-muted); }

/* ===== No results ===== */
.no-results { padding: 60px; text-align: center; color: var(--text-muted); font-size: 16px; }

/* ===== Modal ===== */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#modal {
  background: var(--card-bg); border-radius: 10px; max-width: 700px; width: 95%;
  max-height: 90vh; overflow-y: auto; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-close {
  position: sticky; top: 12px; float: right; margin: 12px 16px;
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted);
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--content-bg); }

.modal-header { padding: 20px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); word-break: break-all; }
.modal-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-family: monospace; }
.modal-body { padding: 16px 20px 20px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-item { }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 2px; }
.detail-value { font-size: 13px; color: var(--text); font-weight: 500; }
.detail-value.mono { font-family: monospace; font-size: 12px; }

.winbox-hint {
  font-size: 11px; color: var(--text-muted); margin: 10px 20px 0;
  padding: 8px 10px; background: #f9fafb; border-radius: 4px;
  border-left: 3px solid var(--border);
}
.modal-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.modal-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 10px; }

.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions a, .modal-actions button {
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
  text-decoration: none; border: none; cursor: pointer;
}
.modal-actions .primary { background: var(--orange); color: #fff; }
.modal-actions .secondary { background: #e5e7eb; color: var(--text); }

/* ===== Stats / Dashboard ===== */
#view-stats { padding: 24px; overflow-y: auto; flex: 1; }
.stats-header { margin-bottom: 20px; }
.stats-header h1 { font-size: 24px; font-weight: 700; }
.stats-header p { color: var(--text-muted); margin-top: 4px; }

.stats-cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.stat-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); min-width: 160px; flex: 1;
}
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: var(--text); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-card .stat-value.orange { color: var(--orange); }
.stat-card .stat-value.green { color: var(--up-color); }
.stat-card .stat-value.red { color: var(--down-color); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.stats-section { background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); }
.stats-section h2 { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px; }

.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label { font-size: 11px; color: var(--text); min-width: 120px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: #f3f4f6; border-radius: 4px; height: 18px; overflow: hidden; cursor: pointer; }
.bar-fill { height: 100%; background: var(--orange); border-radius: 4px; transition: width 0.3s; display: flex; align-items: center; padding: 0 6px; min-width: 24px; }
.bar-fill span { font-size: 10px; font-weight: 700; color: #fff; white-space: nowrap; }
.bar-count { font-size: 11px; color: var(--text-muted); min-width: 30px; text-align: right; }

/* ===== Utilities ===== */
.hidden { display: none !important; }
.loading { opacity: 0.5; }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: monospace; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: #1a1d23; color: #fff; padding: 10px 18px; border-radius: 6px;
  font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: opacity 0.3s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ===== Login screen ===== */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--sidebar-bg);
}
.login-card {
  background: var(--card-bg); border-radius: 12px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-logo { display: flex; align-items: baseline; gap: 0; line-height: 1; }
.login-logo .logo-v { color: var(--orange); font-size: 32px; font-weight: 900; }
.login-logo .logo-text { color: var(--text); font-size: 24px; font-weight: 600; }
.login-subtitle { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 28px; }
.login-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--text); }
.form-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.login-forgot { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.login-forgot a { color: var(--orange); text-decoration: none; }
.login-forgot a:hover { text-decoration: underline; }

/* ===== Form elements ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input, .form-group select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; color: var(--text);
  background: var(--card-bg); transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.15);
}
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 13px; color: var(--text); }
.form-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--orange); }
.form-error { padding: 10px 12px; background: #fee2e2; color: #991b1b; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.form-success { padding: 10px 12px; background: #d1fae5; color: #065f46; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; align-items: center; }

/* ===== Buttons ===== */
.btn-primary {
  width: 100%; padding: 10px; background: var(--orange); color: #fff;
  border: none; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.btn-primary:hover { background: var(--orange-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  padding: 10px 16px; background: #e5e7eb; color: var(--text);
  border: none; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.btn-secondary:hover { background: #d1d5db; }

/* ===== Group badges ===== */
.group-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.group-badge-admin     { background: #fce7f3; color: #9d174d; }
.group-badge-user      { background: #dbeafe; color: #1d4ed8; }
.group-badge-readonly  { background: #f3f4f6; color: #374151; }

/* ===== Sidebar user info & logout ===== */
.user-info { display: flex; align-items: center; gap: 6px; padding: 8px 0 6px; font-size: 12px; color: var(--sidebar-text); }
#sidebar-username { font-weight: 600; color: #e5e7eb; }
.btn-logout {
  width: 100%; background: transparent; color: #6b7280;
  border: 1px solid #374151; border-radius: 4px; padding: 6px;
  font-size: 11px; cursor: pointer; transition: all 0.15s; text-align: center;
}
.btn-logout:hover { background: #374151; color: #e5e7eb; }

/* ===== Admin views ===== */
.admin-header {
  padding: 20px 24px 16px; background: var(--card-bg);
  border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; flex-shrink: 0;
}
.admin-header h1 { font-size: 20px; font-weight: 700; }
.btn-action { padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 600; border: none; cursor: pointer; }
.btn-action.btn-primary { background: var(--orange); color: #fff; width: auto; }

.admin-content { flex: 1; overflow-y: auto; padding: 20px 24px; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--card-bg); font-size: 13px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.admin-table th { background: #f9fafb; border-bottom: 2px solid var(--border); padding: 10px 14px; text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); white-space: nowrap; }
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tbody tr:hover { background: #faf9f7; }

#view-admin-users, #view-admin-smtp, #view-admin-audit { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* ===== Settings form ===== */
.settings-form { max-width: 500px; background: var(--card-bg); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); }
.settings-form .form-group input { background: var(--card-bg); }
.settings-form .btn-primary { width: auto; padding: 10px 24px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.2s; }
  #sidebar.mobile-open { transform: translateX(0); }
  #content { width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  #results-table th:nth-child(4),
  #results-table td:nth-child(4),
  #results-table th:nth-child(6),
  #results-table td:nth-child(6) { display: none; }
}
