/* ==========================================================================
   TokenG Web Terminal - Google Material Design 3 (Material You) Theme
   Faithfully matching the TokenG Android App UI & System Aesthetic
   ========================================================================== */

:root {
  /* Light Theme Palette (Faithfully matching Android TokenG App UI) */
  --md-sys-color-background: #ffffff;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-dim: #f8fafd;
  --md-sys-color-surface-container-low: #f4f7fc;
  --md-sys-color-surface-container: #edf2fa;
  --md-sys-color-surface-container-high: #e2ebf7;
  --md-sys-color-surface-container-highest: #d6e2f5;

  --md-sys-color-on-surface: #1a1c1e;
  --md-sys-color-on-surface-variant: #5f6368;
  --md-sys-color-outline: #c4c7cf;
  --md-sys-color-outline-variant: #e1e3e8;

  --md-sys-color-primary: #0b57d0;
  --md-sys-color-primary-hover: #0842a0;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #d3e3fd;
  --md-sys-color-on-primary-container: #041e49;

  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  --md-sys-color-success: #137333;
  --md-sys-color-success-container: #e6f4ea;
  --md-sys-color-on-success-container: #0d5223;

  --md-avatar-bg: #2b4c7e;
  --md-avatar-fg: #ffffff;

  --font-sans: 'Google Sans', 'Roboto', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Roboto Mono', 'Fira Code', monospace;

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;

  --shadow-elevation-1: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-elevation-2: 0 3px 6px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-elevation-3: 0 10px 20px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  /* Dark Theme Palette (Android 14+ M3 Dark Mode) */
  --md-sys-color-background: #101318;
  --md-sys-color-surface: #181b20;
  --md-sys-color-surface-dim: #13161a;
  --md-sys-color-surface-container-low: #1a1e24;
  --md-sys-color-surface-container: #1e2229;
  --md-sys-color-surface-container-high: #282d36;
  --md-sys-color-surface-container-highest: #333842;

  --md-sys-color-on-surface: #e2e2e9;
  --md-sys-color-on-surface-variant: #c4c6d0;
  --md-sys-color-outline: #44474e;
  --md-sys-color-outline-variant: #2d3139;

  --md-sys-color-primary: #a8c7fa;
  --md-sys-color-primary-hover: #c2e7ff;
  --md-sys-color-on-primary: #041e49;
  --md-sys-color-primary-container: #0842a0;
  --md-sys-color-on-primary-container: #d3e3fd;

  --md-sys-color-error: #ffb4ab;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;

  --md-sys-color-success: #81c995;
  --md-sys-color-success-container: #0f5128;
  --md-sys-color-on-success-container: #ceead6;

  --md-avatar-bg: #3d5a80;
  --md-avatar-fg: #ffffff;

  --shadow-elevation-1: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-elevation-2: 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-elevation-3: 0 12px 24px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline);
  border-radius: 3px;
}

/* --------------------------------------------------------------------------
   App Frame & View Switching
   -------------------------------------------------------------------------- */
.app-container {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--md-sys-color-background);
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (min-width: 768px) {
  .app-container {
    box-shadow: none;
  }
}

.m3-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.view-section {
  display: none;
}
.view-section.active {
  display: block;
}

/* --------------------------------------------------------------------------
   Material 3 Top App Bar
   -------------------------------------------------------------------------- */
.m3-top-app-bar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--md-sys-color-background);
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-bar-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-bar-title {
  font-size: 22px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  letter-spacing: -0.01em;
}

.app-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.status-pill-mini {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
}

.status-dot-mini {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--md-sys-color-success);
}
.status-dot-mini.offline {
  background: var(--md-sys-color-error);
}

/* --------------------------------------------------------------------------
   Material 3 Primary Tabs (Accounts | Cloud Sync)
   -------------------------------------------------------------------------- */
.m3-tabs-bar {
  display: flex;
  background: var(--md-sys-color-background);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  position: sticky;
  top: 64px;
  z-index: 30;
}

.m3-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  gap: 4px;
  position: relative;
  transition: color 0.2s ease;
}

.m3-tab .tab-icon-svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  margin-bottom: 2px;
}

.m3-tab:hover {
  color: var(--md-sys-color-on-surface);
}

.m3-tab.active {
  color: var(--md-sys-color-primary);
  font-weight: 600;
}

.m3-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--md-sys-color-primary);
  border-radius: 3px 3px 0 0;
}

/* --------------------------------------------------------------------------
   Section Headers (Matching TokenG App uppercase blue labels)
   -------------------------------------------------------------------------- */
.content-body {
  padding: 20px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.m3-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-sys-color-primary);
  margin-bottom: 10px;
  padding-left: 6px;
}

/* --------------------------------------------------------------------------
   Material 3 Cards & Group Containers
   -------------------------------------------------------------------------- */
.m3-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: none;
  transition: background-color 0.15s ease;
}

.m3-card-row {
  display: flex;
  align-items: center;
  padding: 16px 18px;
  gap: 16px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  position: relative;
}

.m3-card-row:hover {
  background: var(--md-sys-color-surface-container-high);
}

.m3-card-row:not(:last-child) {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.row-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--md-sys-color-on-surface);
  flex-shrink: 0;
}

.row-text-content {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 2px;
}

.row-subtitle {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.3;
  word-break: break-all;
}

/* --------------------------------------------------------------------------
   Account Card (1:1 Android Parity)
   -------------------------------------------------------------------------- */
.account-card-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-m3-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-lg);
  box-shadow: none;
  overflow: hidden;
  transition: all 0.2s ease;
}

.account-header-click {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 14px;
  cursor: pointer;
  user-select: none;
}

.account-header-click:hover {
  background: var(--md-sys-color-surface-container-high);
}

.account-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-pill);
  background: var(--md-avatar-bg);
  color: var(--md-avatar-fg);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-main-meta {
  flex: 1;
  min-width: 0;
}

.account-name-row {
  font-size: 15px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-email-sub {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 2px;
}

.account-device-sub {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-chevron {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform 0.2s ease;
  margin-left: 8px;
}

.account-m3-card.expanded .account-chevron {
  transform: rotate(180deg);
}

/* Expanded Detail Drawer inside Account Card */
.account-details-panel {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.account-m3-card.expanded .account-details-panel {
  display: block;
}

.token-code-box {
  background: var(--md-sys-color-surface-dim);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--md-sys-color-on-surface);
  line-height: 1.6;
  word-break: break-all;
}

.code-field-line {
  margin-bottom: 4px;
}
.code-field-line:last-child {
  margin-bottom: 0;
}
.code-field-key {
  color: var(--md-sys-color-on-surface-variant);
}
.code-field-val {
  font-weight: 600;
}

.account-actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.btn-pill {
  flex: 1;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border: none;
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-pill:hover {
  background: var(--md-sys-color-outline-variant);
}

.btn-pill.primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.btn-pill.primary:hover {
  background: var(--md-sys-color-primary-hover);
}

/* --------------------------------------------------------------------------
   Search & Filter Bar (Accounts Tab)
   -------------------------------------------------------------------------- */
.search-pill-bar {
  display: flex;
  align-items: center;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-pill);
  padding: 6px 16px;
  gap: 10px;
  box-shadow: var(--shadow-elevation-1);
}

.search-pill-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
  outline: none;
}

.filter-chips-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.filter-chip {
  background: transparent;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-chip.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Cloud Sync Tab Components
   -------------------------------------------------------------------------- */
.metrics-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.metric-m3-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-elevation-1);
}

.metric-m3-val {
  font-size: 26px;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  margin-bottom: 2px;
}

.metric-m3-lbl {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

/* --------------------------------------------------------------------------
   Auth / Login Screen (Clean M3 Design)
   -------------------------------------------------------------------------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-m3-dialog {
  width: 100%;
  max-width: 440px;
  background: var(--md-sys-color-surface);
  border-radius: 28px;
  padding: 32px 28px;
  box-shadow: var(--shadow-elevation-3);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.auth-app-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin: 0 auto 16px;
  display: block;
}

.auth-title-large {
  font-size: 22px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  text-align: center;
  margin-bottom: 6px;
}

.auth-desc-sub {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  margin-bottom: 24px;
}

.m3-text-field {
  margin-bottom: 18px;
}

.m3-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
  padding-left: 2px;
}

.m3-input {
  width: 100%;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.m3-input:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

.btn-m3-filled {
  width: 100%;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px 20px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-elevation-1);
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn-m3-filled:hover:not(:disabled) {
  background: var(--md-sys-color-primary-hover);
  box-shadow: var(--shadow-elevation-2);
}

.btn-m3-filled:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Inspector Modal (M3 Full Dialog)
   -------------------------------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.m3-dialog-card {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--md-sys-color-surface);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow-elevation-3);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.m3-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.m3-dialog-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.m3-details-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
}

.m3-details-table tr {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.m3-details-table td {
  padding: 10px 8px;
  font-size: 13px;
  vertical-align: top;
}

.m3-key-col {
  width: 35%;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  font-size: 12px;
}

.m3-val-col {
  color: var(--md-sys-color-on-surface);
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   Auto-Lock Overlay
   -------------------------------------------------------------------------- */
.lock-screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(16, 19, 24, 0.96);
  backdrop-filter: blur(12px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lock-screen.active {
  display: flex;
}

.lock-m3-card {
  width: 100%;
  max-width: 380px;
  background: var(--md-sys-color-surface);
  border-radius: 28px;
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow-elevation-3);
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  width: auto;
  max-width: 90vw;
}

.m3-snackbar {
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-elevation-2);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: m3-snack-up 0.2s ease;
}

@keyframes m3-snack-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
