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

:root {
  --bg: #0f0f10;
  --surface: #1a1a1b;
  --surface-hover: #222223;
  --border: #2a2a2b;
  --text: #e5e5e5;
  --text-secondary: #888;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Views */
.view {
  min-height: 100vh;
}

/* Auth */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-mark {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #25f4ee, #fe2c55);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 28px;
  margin: 0 auto 16px;
}

.logo-mark.small {
  width: 36px;
  height: 36px;
  font-size: 18px;
  border-radius: 10px;
  margin: 0;
}

.logo h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.logo p {
  color: var(--text-secondary);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
}

.auth-form input::placeholder {
  color: #555;
}

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  font-size: 13px;
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-connect {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
  white-space: nowrap;
}

.btn-connect:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* Dashboard */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  font-weight: 600;
  font-size: 16px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-email {
  color: var(--text-secondary);
  font-size: 14px;
}

.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.welcome {
  margin-bottom: 32px;
}

.welcome h2 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 16px;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.platform-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}

.platform-card:hover {
  border-color: #3a3a3b;
  transform: translateY(-2px);
}

.platform-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.platform-info {
  flex: 1;
  min-width: 0;
}

.platform-info h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}

.platform-desc {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 6px;
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-badge.connected {
  background: rgba(16, 163, 127, 0.15);
  color: var(--accent);
}

.status-badge.disconnected {
  background: rgba(136, 136, 136, 0.1);
  color: var(--text-secondary);
}

.status-badge.expired {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

/* Connection form in modal */
.connect-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.connect-form h3 {
  margin-bottom: 8px;
}

.connect-form p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 8px;
}

.connect-form label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.connect-form input {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.connect-form input:focus {
  border-color: var(--accent);
}

.connect-form .btn-primary {
  margin-top: 8px;
}

.instructions {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.instructions code {
  background: #2a2a2b;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', monospace;
  font-size: 12px;
}

@media (max-width: 640px) {
  .platform-grid {
    grid-template-columns: 1fr;
  }
  .auth-card {
    padding: 28px 20px;
  }
}

/* Usage bar */
.usage-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.usage-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.plan-badge {
  background: var(--accent);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.usage-text {
  color: var(--text-secondary);
  font-size: 13px;
}

.usage-bar-track {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.usage-bar-fill.warning {
  background: #f59e0b;
}

.usage-bar-fill.danger {
  background: #dc2626;
}

/* Header nav */
.header-nav {
  display: flex;
  gap: 4px;
  margin-right: 16px;
}

.nav-link {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--text);
}

.nav-link.active {
  background: var(--bg);
  color: var(--text);
}

/* Invoices */
.invoices-section, .admin-section {
  margin-top: 24px;
}

.invoices-section h3, .admin-section h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.invoices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invoice-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}

.invoice-item .inv-num {
  font-weight: 600;
  font-size: 14px;
}

.invoice-item .inv-period {
  color: var(--text-secondary);
  font-size: 12px;
}

.invoice-item .inv-amount {
  font-weight: 700;
  font-size: 16px;
}

.invoice-item .inv-status {
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.inv-status.draft { background: rgba(136,136,136,0.1); color: #888; }
.inv-status.sent { background: rgba(245,158,11,0.15); color: #f59e0b; }
.inv-status.paid { background: rgba(16,163,127,0.15); color: var(--accent); }
.inv-status.overdue { background: rgba(220,38,38,0.15); color: #dc2626; }

/* Admin */
.admin-customers {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-secondary);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

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

.admin-table .btn-small {
  padding: 4px 10px;
  font-size: 11px;
}

/* Analytics */
.analytics-section {
  margin-top: 24px;
}

.section-title {
  font-size: 18px;
  margin-bottom: 4px;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  height: 220px;
}

.analytics-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Webhooks */
.webhooks-section {
  margin-top: 24px;
}

.webhook-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
}

.webhook-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.webhook-url-display {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  word-break: break-all;
}

.webhook-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.webhook-form input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.webhook-form input:focus {
  border-color: var(--accent);
}

.webhook-secret-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}

.webhook-secret-label {
  font-size: 12px;
  color: #f59e0b;
  margin-bottom: 8px;
}

.webhook-secret-value {
  font-family: 'SF Mono', monospace;
  font-size: 12px;
  word-break: break-all;
  margin-bottom: 8px;
  color: var(--text);
}

.webhook-instructions {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.webhook-instructions code {
  background: #2a2a2b;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', monospace;
  font-size: 12px;
}

/* Password reset */
.success-msg {
  color: var(--accent);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}
