.modal { display: none; position: fixed; inset: 0; z-index: 200; overflow-y: auto; padding: 40px 20px; padding-top: calc(40px + var(--safe-area-inset-top)); padding-bottom: calc(40px + var(--safe-area-inset-bottom)); }
.modal.active { display: flex; justify-content: center; align-items: flex-start; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); animation: fadeIn 0.2s ease; }

.modal-panel { position: relative; background: var(--surface-1); border: 1px solid var(--border-1); border-radius: var(--radius-xl); width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); animation: modalIn 0.3s cubic-bezier(0.4,0,0.2,1); overflow: hidden; margin: auto; }
.modal-panel--wide { max-width: 600px; }

.modal-close { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: var(--radius-sm); background: none; border: none; color: var(--text-tertiary); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2; transition: all var(--transition-fast); }
.modal-close:hover { background: var(--surface-2); color: var(--text-primary); }

.modal-body { padding: 36px 32px 32px; }
.login-logo { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent); margin-bottom: 20px; }
.modal-title { font-size: 20px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; letter-spacing: -0.2px; }
.modal-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 24px; }

/* OAuth button */
.oauth-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px; background: var(--accent); border: none; border-radius: var(--radius-md);
  color: white; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all var(--transition-fast); font-family: inherit; margin-bottom: 16px;
}
.oauth-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 14px var(--accent-glow); }

.login-divider { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; color: var(--text-muted); font-size: 14px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-1); }

.api-key-section { display: flex; flex-direction: column; gap: 8px; }
.input-label { font-size: 14px; font-weight: 500; color: var(--text-secondary); }
.api-key-input-wrap { position: relative; }
.api-key-input-wrap input {
  width: 100%; padding: 10px 40px 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border-1); border-radius: var(--radius-md);
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none; transition: all var(--transition-fast);
}
.api-key-input-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.api-key-input-wrap input::placeholder { color: var(--text-muted); }
.api-key-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 6px; background: none; border: none; color: var(--text-tertiary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast); }
.api-key-toggle:hover { background: var(--surface-3); color: var(--text-primary); }
.api-key-btn {
  width: 100%; padding: 10px; background: var(--surface-2); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); color: var(--text-primary); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all var(--transition-fast); font-family: inherit;
}
.api-key-btn:hover { background: var(--surface-3); border-color: var(--border-2); }
.api-key-hint { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* Settings */
.settings-grid { display: flex; flex-direction: column; gap: 20px; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.3px; }

.theme-toggle { display: flex; gap: 8px; }
.theme-option {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; background: var(--surface-2); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); color: var(--text-secondary); font-size: 14px;
  cursor: pointer; transition: all var(--transition-fast); font-family: inherit;
}
.theme-option:hover { background: var(--surface-3); }
.theme-option.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.theme-option svg { color: currentColor; }

.model-select-wrap { position: relative; }
.model-select-wrap select {
  width: 100%; appearance: none; padding: 10px 36px 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); color: var(--text-primary);
  font-size: 14px; font-family: inherit; cursor: pointer; outline: none;
  transition: all var(--transition-fast);
}
.model-select-wrap select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.select-chevron { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); pointer-events: none; }

.account-info { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.account-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-1); }
.account-row:last-child { border-bottom: none; }
.account-label { font-size: 14px; color: var(--text-tertiary); }
.account-value { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.setting-btn {
  width: 100%; padding: 10px; background: var(--danger);
  border: none; border-radius: var(--radius-md); color: white;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all var(--transition-fast); font-family: inherit;
}
.setting-btn:hover { background: #dc2626; }

/* Toast */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(100px);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; background: var(--surface-1);
  border: 1px solid var(--border-1); border-radius: var(--radius-lg);
  color: var(--text-primary); font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); z-index: 300; opacity: 0;
  transition: all 0.3s cubic-bezier(0.4,0,0.2,1); pointer-events: none;
}
.toast.active { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast svg { color: var(--success); flex-shrink: 0; }

/* Usage Modal Specific Styles */
.usage-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: usage-spin 0.8s linear infinite;
}

@keyframes usage-spin {
  to { transform: rotate(360deg); }
}

.usage-progress-container {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.usage-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.usage-progress-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.usage-progress-percentage {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.usage-progress-bar-wrap {
  height: 10px;
  background: var(--surface-3);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 10px;
}

.usage-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, #a855f7 100%);
  border-radius: 5px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
}

.usage-progress-footer {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}

.usage-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.usage-metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.usage-metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-2);
}

.usage-metric-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.usage-metric-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.usage-breakdown-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@media (max-width: 768px) {
  .usage-breakdown-section {
    display: none;
  }
}

.usage-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.1px;
}

.usage-table-wrap {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  max-height: 250px;
  overflow-y: auto;
  background: var(--surface-2);
}

.usage-table thead {
  display: none;
}

.usage-table, 
.usage-table tbody, 
.usage-table tr, 
.usage-table td {
  display: block;
  width: 100% !important;
}

.usage-table tr {
  border-bottom: 1px solid var(--border-2);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.usage-table tr:last-child {
  border-bottom: none;
}

.usage-table td {
  border-bottom: none;
  padding: 0 !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

/* Style first column as the card header */
.usage-table td:first-child {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  justify-content: flex-start;
}

.usage-table td:first-child > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Add inline text labels for other columns */
.usage-table td:not(:first-child)::before {
  content: attr(data-label);
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.usage-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-tertiary);
}

.usage-plan-btn {
  padding: 6px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.usage-plan-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

/* Skeleton Loader Styles */
.skeleton-text {
  background: var(--surface-3);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  transition: opacity 0.2s ease-in-out;
  opacity: 1;
}

.skeleton-text.fade-out-skeleton {
  opacity: 0 !important;
}

.skeleton-text::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.05) 20%,
    rgba(255, 255, 255, 0.1) 60%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: skeleton-shimmer 1.5s infinite;
}

[data-theme="light"] .skeleton-text::after {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.03) 20%,
    rgba(0, 0, 0, 0.06) 60%,
    rgba(0, 0, 0, 0) 100%
  );
}

.usage-progress-bar.skeleton-progress {
  background: var(--surface-3) !important;
  box-shadow: none !important;
  position: relative;
  overflow: hidden;
}

.usage-progress-bar.skeleton-progress::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.05) 20%,
    rgba(255, 255, 255, 0.1) 60%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: skeleton-shimmer 1.5s infinite;
}

[data-theme="light"] .usage-progress-bar.skeleton-progress::after {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.03) 20%,
    rgba(0, 0, 0, 0.06) 60%,
    rgba(0, 0, 0, 0) 100%
  );
}

@keyframes skeleton-shimmer {
  100% {
    transform: translateX(100%);
  }
}

@keyframes fadeInVal {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-val {
  display: inline-block;
  animation: fadeInVal 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
