*, *::before, *::after { box-sizing: border-box; }

:root {
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --radius-card:  8px;
  --radius-input: 6px;
  --header-h:     56px;
}

[data-theme="light"] {
  --bg:            #F8FAFC;
  --surface:       #FFFFFF;
  --surface-hover: #F1F5F9;
  --border:        #E2E8F0;
  --text:          #0F172A;
  --text-muted:    #64748B;
  --accent:        #6366F1;
  --accent-hover:  #4F46E5;
  --accent-subtle: rgba(99, 102, 241, 0.1);
  --danger:        #EF4444;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

[data-theme="dark"] {
  --bg:            #0F172A;
  --surface:       #1E293B;
  --surface-hover: #273344;
  --border:        #334155;
  --text:          #F1F5F9;
  --text-muted:    #94A3B8;
  --accent:        #818CF8;
  --accent-hover:  #6366F1;
  --accent-subtle: rgba(129, 140, 248, 0.12);
  --danger:        #F87171;
  --shadow:        0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.2px; }
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-subtle); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11px; letter-spacing: 0.5px;
}
.user-name { font-size: 13px; color: var(--text-muted); }
.theme-btn {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-input); color: var(--text-muted);
  cursor: pointer; padding: 5px 9px; font-size: 14px;
  display: flex; align-items: center; line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.theme-btn:hover { background: var(--surface-hover); color: var(--text); }
.logout-link { font-size: 12px; color: var(--text-muted); }
.logout-link:hover { color: var(--text); }

.main {
  margin-top: var(--header-h);
  padding: 28px 24px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 18px; font-weight: 600; margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--radius-input); padding: 7px 14px;
  font-size: 13px; font-weight: 500; font-family: var(--font);
  cursor: pointer; border: none; line-height: 1;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: none; border: 1px solid var(--border); color: var(--text-muted); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px 6px; border-radius: 4px;
  display: inline-flex; align-items: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon.danger:hover { color: var(--danger); background: rgba(239,68,68,0.08); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow); overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted);
  padding: 10px 14px; text-align: left;
  border-bottom: 2px solid var(--accent);
  background: var(--surface); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }
tbody td { padding: 10px 14px; font-size: 13px; vertical-align: top; }
.app-name-row { display: flex; align-items: center; font-weight: 600; }
.app-name { font-weight: 600; }
.app-desc { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.actions-cell { white-space: nowrap; text-align: right; }

.link-cell { display: flex; flex-direction: column; gap: 5px; }
.link-cell-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stale-pill {
  display: inline-block; padding: 1px 6px;
  background: #FF5000; color: #fff;
  font-size: 10px; font-weight: 600; letter-spacing: 0.5px;
  border-radius: 3px;
}
.last-seen { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.link-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-subtle); color: var(--accent);
  border-radius: 4px; padding: 2px 8px; font-size: 12px; font-weight: 500;
  text-decoration: none; width: fit-content; transition: opacity 0.15s;
}
.link-pill:hover { opacity: 0.75; text-decoration: none; color: var(--accent); }
.link-pill.grafana { background: rgba(242,132,74,0.1); color: #E87040; font-size: 11px; }
[data-theme="dark"] .link-pill.grafana { color: #F2974A; }
.cell-empty { color: var(--text-muted); }

.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.55); z-index: 200;
  align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 24px;
  width: 560px; max-width: 100%;
  max-height: calc(100vh - 32px); overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 16px; font-weight: 600; margin: 0; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); margin-bottom: 5px;
}
.form-input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-input);
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.form-input::placeholder { color: var(--text-muted); }
.form-section {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--accent);
  margin: 16px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; display: none; }

.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 300; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-input); padding: 10px 16px; font-size: 13px;
  box-shadow: var(--shadow); animation: toastIn 0.2s ease; pointer-events: auto;
}
.toast.success { border-left: 3px solid #22C55E; }
.toast.error   { border-left: 3px solid var(--danger); }
@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 40px 36px;
  width: 360px; max-width: calc(100vw - 32px);
  text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
.login-logo { margin-bottom: 16px; }
.login-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; color: var(--text); }
.login-subtitle { color: var(--text-muted); font-size: 13px; margin: 0 0 28px; }
.login-error {
  background: rgba(239,68,68,0.08); border: 1px solid var(--danger);
  color: var(--danger); border-radius: var(--radius-input);
  padding: 10px 12px; font-size: 13px; margin-bottom: 16px; text-align: left;
}
.btn-google {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #3c4043; border: 1px solid #dadce0;
  border-radius: 4px; padding: 10px 24px;
  font-size: 14px; font-weight: 500; font-family: var(--font);
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-google:hover {
  background: #f8f9fa; box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  text-decoration: none; color: #3c4043;
}

/* ── Responsive / Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Topbar: tighter padding, hide first name */
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar-title { font-size: 14px; }
  .user-name { display: none; }

  /* Main: tighter padding */
  .main { padding: 16px 12px; }

  /* Table: horizontal scroll so all columns remain accessible */
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 540px; }

  /* Form rows collapse to single column */
  .form-row { grid-template-columns: 1fr; }

  /* Inputs: 16px prevents iOS auto-zoom on focus */
  .form-input { font-size: 16px; }

  /* Modal: bottom sheet — slides up from bottom edge */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    max-height: 88vh;
    padding: 20px 16px;
  }

  /* Icon buttons: larger touch targets */
  .btn-icon {
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
  }

  /* Toast: span full width */
  .toast-container { right: 12px; left: 12px; bottom: 16px; }
}

/* ── App column metadata ──────────────────────────────────────────────────── */
.app-meta {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 5px; margin-top: 5px;
}

.version-badge {
  display: inline-flex; align-items: center; align-self: flex-start; gap: 4px;
  background: var(--accent); color: #fff;
  border-radius: 4px; padding: 1px 7px;
  font-size: 11px; font-weight: 600;
}
a.version-badge-link { text-decoration: none; transition: opacity 0.15s; }
a.version-badge-link:hover { opacity: 0.75; color: #fff; }

.tech-tag {
  display: inline-flex; align-items: center;
  background: var(--surface-hover); color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-size: 11px;
}

.commit-time { font-size: 11px; color: var(--text-muted); }

.audit-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0; cursor: default;
}
.audit-dot.green  { background: #22C55E; }
.audit-dot.amber  { background: #F59E0B; }
.audit-dot.red    { background: var(--danger); }
.audit-dot.none   { background: var(--border); }

/* ── DataTables theme overrides ───────────────────────────────────────────── */
.dataTables_wrapper { font-size: 13px; color: var(--text); }

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 4px 8px; font-size: 13px;
  font-family: var(--font); outline: none;
}
.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
  color: var(--text-muted); font-size: 12px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  background: none !important; border: none !important;
  color: var(--text-muted) !important;
  border-radius: 4px; padding: 3px 8px; cursor: pointer;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--surface-hover) !important;
  color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--accent) !important;
  color: #fff !important; border-radius: 4px;
}

table.dataTable thead th {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  border-bottom: 2px solid var(--accent) !important;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.6px; font-weight: 600;
  padding: 8px 10px;
}
table.dataTable tbody tr { border-bottom: 1px solid var(--border); }
table.dataTable tbody tr:hover > * {
  background: var(--surface-hover) !important;
}
table.dataTable tbody td {
  padding: 8px 10px; font-size: 13px; color: var(--text);
}

/* ── History modal (wider) ────────────────────────────────────────────────── */
.modal-wide { width: 920px; }

/* ── Show/hide apps ─────────────────────────────────────────────────────── */
.row-hidden { opacity: 0.4; }
.row-hidden:hover { opacity: 0.65; }
