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

:root {
  --bg:          #1a1d23;
  --sidebar:     #141720;
  --card:        #22263a;
  --header:      #0f1117;
  --accent:      #3b82f6;
  --accent-dark: #2563eb;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --purple:      #a855f7;
  --teal:        #14b8a6;
  --text:        #e2e8f0;
  --muted:       #64748b;
  --border:      #2d3148;
  --input:       #0f1117;
  --radius:      10px;
  --font:        'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-app-region: no-drag;
}

#app { height: 100vh; display: flex; flex-direction: column; }

/* ── Loading screen ── */
#loading-screen {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
}
.loading-logo  { font-size: 64px; color: var(--accent); animation: pulse 1.5s ease-in-out infinite; }
.loading-text  { font-size: 24px; font-weight: 800; color: var(--text); }
.loading-sub   { font-size: 13px; color: var(--muted); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── App shell ── */
#shell { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Title bar (custom) ── */
#titlebar {
  height: 40px; background: var(--header);
  display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
  flex-shrink: 0;
}
#titlebar .logo  { font-size: 20px; color: var(--accent); -webkit-app-region: no-drag; }
#titlebar .title { font-size: 14px; font-weight: 700; color: var(--text); }
#titlebar .conn  { margin-left: auto; font-size: 12px; display: flex; align-items: center; gap: 6px; -webkit-app-region: no-drag; }
#titlebar .conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
#titlebar .conn-dot.connected { background: var(--success); }
#titlebar .conn-url { color: var(--muted); font-size: 11px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Nav tabs ── */
#navtabs {
  display: flex; background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.navtab {
  padding: 10px 22px; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; transition: all .15s;
  display: flex; align-items: center; gap: 7px;
}
.navtab:hover  { color: var(--text); background: rgba(255,255,255,.04); }
.navtab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--bg); }

/* ── Tab content ── */
#content { flex: 1; display: flex; overflow: hidden; }
.tab-panel { flex: 1; display: none; overflow: hidden; }
.tab-panel.active { display: flex; }

/* ── Inventory tab: split layout ── */
#inv-panel { flex-direction: row; }
#inv-list  { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#inv-detail {
  width: 320px; background: var(--sidebar);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  flex-shrink: 0;
}

/* ── Toolbar ── */
.toolbar {
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.search-input {
  flex: 1; background: var(--input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 12px; font-size: 13px; font-family: var(--font);
  outline: none; transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }

/* filter chips */
.chips { display: flex; gap: 6px; flex-shrink: 0; }
.chip {
  padding: 5px 13px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.chip:hover  { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.count-label { font-size: 11px; color: var(--muted); white-space: nowrap; margin-left: auto; }

/* ── Inventory table ── */
#inv-table-wrap { flex: 1; overflow-y: auto; }
#inv-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
#inv-table th {
  background: var(--header); color: var(--muted); font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 10px 14px; text-align: left; position: sticky; top: 0;
  cursor: pointer; user-select: none; border-bottom: 1px solid var(--border);
}
#inv-table th:hover { color: var(--text); }
#inv-table td { padding: 10px 14px; border-bottom: 1px solid rgba(45,49,72,.5); }
#inv-table tr:hover td { background: rgba(59,130,246,.06); cursor: pointer; }
#inv-table tr.selected td { background: rgba(59,130,246,.14); }

/* status badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 700;
}
.badge-FUNCTIONAL { background:#14432a; color:#22c55e; }
.badge-FAILED     { background:#3d1414; color:#ef4444; }
.badge-LOST       { background:#3d2e00; color:#f59e0b; }
.badge-default    { background:var(--card); color:var(--muted); }

/* detail panel */
.detail-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  background: var(--header); flex-shrink: 0;
}
.detail-header h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.detail-header .sub { font-size: 12px; color: var(--muted); }
.detail-rows { flex: 1; overflow-y: auto; padding: 12px; }
.detail-row {
  display: flex; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid rgba(45,49,72,.5);
}
.detail-row .lbl {
  width: 110px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; color: var(--muted); flex-shrink: 0;
}
.detail-row .val { font-size: 13px; color: var(--text); flex: 1; word-break: break-word; }
.detail-actions { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.detail-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-size: 13px;
}
.detail-empty .icon { font-size: 36px; }

/* ── Buttons ── */
.btn {
  padding: 9px 18px; border-radius: var(--radius); border: none;
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all .15s; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary  { background: var(--accent);   color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-dark); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover:not(:disabled)  { background: #16a34a; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #dc2626; }
.btn-purple   { background: var(--purple);   color: #fff; }
.btn-teal     { background: var(--teal);     color: #fff; }
.btn-ghost    { background: var(--card);     color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 6px 12px; font-size: 12px; }

/* ── Add Device tab ── */
#add-panel { flex-direction: row; gap: 0; }
#add-left {
  width: 420px; flex-shrink: 0; padding: 20px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
#add-right { flex: 1; padding: 20px; overflow-y: auto; }

.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted); margin-bottom: 8px;
}

/* image preview box */
#img-preview-box {
  width: 100%; height: 220px; background: var(--card);
  border: 2px dashed var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: var(--muted);
  overflow: hidden; flex-shrink: 0;
}
#img-preview-box img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 8px;
}
#img-preview-box .placeholder { font-size: 40px; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* barcode row */
.barcode-row { display: flex; gap: 8px; align-items: flex-end; }
.barcode-row input { flex: 1; }

/* form group */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted);
}
.form-input, .form-select {
  background: var(--input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: 14px; font-family: var(--font);
  outline: none; transition: border-color .15s; width: 100%;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--muted); }
.form-select option { background: var(--card); color: var(--text); }

/* status chips */
.status-chips { display: flex; gap: 8px; }
.status-chip {
  flex: 1; padding: 9px; text-align: center; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--card);
  font-size: 11px; font-weight: 700; color: var(--muted); cursor: pointer;
  transition: all .15s;
}
.status-chip.active-FUNCTIONAL { background:#14432a; border-color:#22c55e; color:#22c55e; }
.status-chip.active-FAILED     { background:#3d1414; border-color:#ef4444; color:#ef4444; }
.status-chip.active-LOST       { background:#3d2e00; border-color:#f59e0b; color:#f59e0b; }

/* dynamic field rows */
#dynamic-fields .field-row { margin-bottom: 12px; }

/* result message */
.result-msg {
  padding: 12px; border-radius: var(--radius); font-size: 13px;
  font-weight: 600; text-align: center; margin-top: 8px;
}
.result-msg.ok  { background: #14432a; color: #22c55e; }
.result-msg.err { background: #3d1414; color: #ef4444; }

/* ── Settings tab ── */
#settings-panel { overflow-y: auto; }
.settings-inner { max-width: 640px; margin: 0 auto; padding: 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.stat-num  { font-size: 28px; font-weight: 800; }
.stat-lbl  { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin-top: 4px; }
.about-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.about-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.about-card p  { font-size: 13px; color: var(--muted); line-height: 1.7; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; width: 500px; max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(20px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; background: var(--header);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-tab {
  flex: 1; padding: 10px; text-align: center; font-size: 13px;
  font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s; background: none; border: none;
  border-bottom: 2px solid transparent;
}
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.modal-body { flex: 1; overflow-y: auto; padding: 12px; }
.assignee-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 6px; cursor: pointer;
  transition: border-color .15s;
}
.assignee-row:hover { border-color: var(--accent); }
.assignee-name { font-size: 14px; font-weight: 600; }
.assignee-arrow { color: var(--accent); font-size: 14px; }

/* ── Login screen ── */
#login-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 36px; width: 420px;
}
.login-logo { font-size: 52px; text-align: center; color: var(--accent); margin-bottom: 8px; }
.login-title { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 28px; }
.login-hint  { font-size: 11px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }

/* ── Scrollbar styling ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Toast notifications ── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 13px; font-weight: 600; max-width: 340px;
  animation: slideIn .2s ease; display: flex; align-items: center; gap: 8px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { transform:translateX(100%); opacity:0; } to { transform:translateX(0); opacity:1; } }

/* ── Spinner ── */
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty table state */
.empty-row td {
  text-align: center; padding: 48px; color: var(--muted); font-size: 14px;
}
