:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #14213d;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b91c1c;
  --border: #e2e8f0;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
.topbar { height: 64px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.brand-mark { background: var(--primary); color: white; border-radius: 10px; padding: 8px 10px; font-size: 12px; letter-spacing: .06em; }
.nav { display: flex; align-items: center; gap: 12px; }
.nav a, .inline-form button, .ghost-btn { border: 1px solid var(--border); background: white; padding: 9px 12px; border-radius: 10px; cursor: pointer; }
.nav a.active { background: #ecfdf5; border-color: #99f6e4; color: var(--primary-dark); }
.inline-form { margin: 0; }
.container { max-width: 1120px; margin: 0 auto; padding: 28px 18px; }
.alert { margin-bottom: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid; }
.alert.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.auth-card { max-width: 460px; margin: 70px auto; background: var(--card); border: 1px solid var(--border); border-radius: 22px; padding: 28px; box-shadow: 0 20px 45px rgba(15, 23, 42, .08); }
.auth-card h1, .page-head h1 { margin: 0 0 8px; }
.auth-card p, .page-head p, .panel p { color: var(--muted); }
.form-card { display: grid; gap: 16px; margin-top: 24px; }
label { display: grid; gap: 8px; font-weight: 600; }
input { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 12px 13px; font-size: 15px; }
.primary-btn { border: 0; background: var(--primary); color: white; padding: 13px 15px; border-radius: 12px; font-weight: 700; cursor: pointer; }
.primary-btn:hover { background: var(--primary-dark); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card, .panel { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: 0 10px 25px rgba(15, 23, 42, .04); }
.stat-card span { color: var(--muted); display: block; margin-bottom: 12px; }
.stat-card strong { font-size: 32px; }
.table-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.table-list li { background: #f1f5f9; border: 1px solid var(--border); padding: 8px 10px; border-radius: 999px; }
code, pre { background: #0f172a; color: #e2e8f0; padding: 2px 6px; border-radius: 6px; }
pre { overflow: auto; padding: 16px; }
@media (max-width: 860px) { .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .page-head { align-items: flex-start; flex-direction: column; } }
@media (max-width: 560px) { .cards-grid { grid-template-columns: 1fr; } .topbar { padding: 0 12px; } .brand span:last-child { display: none; } }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header h1 { margin: 0 0 8px; }
.page-header p { color: var(--muted); margin: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; color: var(--primary) !important; font-size: 12px; font-weight: 800; margin-bottom: 6px !important; }
.grid { display: grid; gap: 18px; }
.two-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.form-stack { display: grid; gap: 14px; }
select, textarea { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 12px 13px; font-size: 15px; font-family: inherit; background: white; }
.button { border: 0; padding: 12px 14px; border-radius: 12px; font-weight: 700; cursor: pointer; }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-dark); }
.mt { margin-top: 18px; }
.status-box { display: grid; gap: 8px; padding: 14px; border-radius: 14px; border: 1px solid var(--border); margin-bottom: 14px; }
.status-box.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.status-box.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.json-preview { max-height: 360px; white-space: pre-wrap; word-break: break-word; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--border); text-align: left; padding: 11px 9px; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.error-cell { max-width: 320px; color: var(--danger); }
@media (max-width: 860px) { .two-cols { grid-template-columns: 1fr; } .page-header { align-items: flex-start; flex-direction: column; } }
.checkbox-line { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 10px; font-weight: 600; }
.checkbox-line input { width: auto; }
.button.muted { display: inline-flex; justify-content: center; border: 1px solid var(--border); background: white; color: var(--text); }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mini-btn { border: 1px solid var(--border); background: white; padding: 7px 9px; border-radius: 9px; cursor: pointer; font-size: 13px; display: inline-flex; }
.mini-btn:hover { background: #f8fafc; }
.table-responsive { overflow-x: auto; }
.badge.pending { background: #fef9c3; color: #854d0e; }
.badge.processing { background: #dbeafe; color: #1d4ed8; }
.badge.sent { background: #dcfce7; color: #166534; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.badge.cancelled { background: #f1f5f9; color: #475569; }
.soft-panel { background: #f8fafc; }
.small-btn { padding: 6px 9px !important; border-radius: 8px !important; font-size: 12px; }
.danger-btn { border: 1px solid #fecaca !important; background: #fef2f2 !important; color: #991b1b !important; }
.danger-btn:hover { background: #fee2e2 !important; }
.compact-cards .stat-card { padding: 14px; }
.compact-cards .stat-card strong { font-size: 24px; }
.user-chip { color: var(--muted); font-size: 13px; border-left: 1px solid var(--border); padding-left: 10px; }
.dashboard-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.filters-row { display: grid; grid-template-columns: 150px 160px 180px minmax(180px, 1fr) auto; gap: 12px; align-items: end; }
.filter-actions { display: flex; gap: 8px; align-items: center; }
.details-list { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 10px 14px; }
.details-list dt { color: var(--muted); font-weight: 700; }
.details-list dd { margin: 0; }
.light-pre { background: #f8fafc; color: var(--text); border: 1px solid var(--border); }
.light-pre code { background: transparent; color: inherit; padding: 0; }
.mini-json { max-width: 360px; max-height: 140px; overflow: auto; font-size: 12px; padding: 8px; }
.text-danger { color: var(--danger) !important; }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
@media (max-width: 1080px) { .dashboard-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .filters-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .filters-row { grid-template-columns: 1fr; } .details-list { grid-template-columns: 1fr; } .nav { overflow-x: auto; } }

/* Phase 7 fixes */
.inline-form button.primary-btn,
.inline-form button.button.primary {
  background: var(--primary) !important;
  color: white !important;
  border-color: var(--primary) !important;
  white-space: nowrap;
}
.inline-form button.primary-btn:hover,
.inline-form button.button.primary:hover { background: var(--primary-dark) !important; }
.page-actions { justify-content: flex-end; min-width: max-content; }
.fixed-page-head { align-items: flex-start; }
.muted-text { color: var(--muted); margin: 0; }
.badge.not_configured { background: #f1f5f9; color: #475569; }
.badge.pending, .badge.processing { background: #fef9c3; color: #854d0e; }
.badge.sent { background: #dcfce7; color: #166534; }
.badge.failed { background: #fee2e2; color: #991b1b; }

/* Phase 8: mobile dashboard navigation + responsive refinements */
html, body { max-width: 100%; overflow-x: hidden; }
.topbar {
  gap: 14px;
}
.nav {
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.nav a,
.nav .inline-form button,
.nav .ghost-btn {
  white-space: nowrap;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-head > div,
.page-header > div {
  min-width: 0;
}
.table-wrap,
.table-responsive {
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 920px) {
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
    position: static;
  }
  .brand {
    width: 100%;
    justify-content: space-between;
  }
  .brand span:last-child {
    display: inline;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 86px);
  }
  .nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }
  .nav a,
  .nav .inline-form button {
    width: 100%;
    text-align: center;
    justify-content: center;
    padding: 9px 8px;
    font-size: 14px;
  }
  .nav .inline-form { width: 100%; }
  .user-chip {
    grid-column: 1 / -1;
    border-left: 0;
    padding-left: 0;
    text-align: center;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
  }
  .container {
    padding: 22px 14px;
  }
  .page-head,
  .page-header,
  .fixed-page-head {
    align-items: stretch !important;
    flex-direction: column;
  }
  .page-actions {
    width: 100%;
    justify-content: stretch;
  }
  .page-actions > *,
  .page-actions .inline-form,
  .page-actions button,
  .page-actions a {
    flex: 1 1 auto;
  }
}

@media (max-width: 560px) {
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .brand span:last-child {
    display: inline;
    font-size: 14px;
  }
  .cards-grid,
  .dashboard-cards,
  .compact-cards {
    grid-template-columns: 1fr !important;
  }
  .stat-card strong { font-size: 26px; }
  .stat-card, .panel { border-radius: 16px; padding: 15px; }
  .auth-card { margin: 38px auto; padding: 22px; }
  input, select, textarea { font-size: 16px; }
  th, td { padding: 10px 8px; }
  .mini-json { max-width: 260px; }
}

@media (max-width: 380px) {
  .nav { grid-template-columns: 1fr; }
  .page-actions { flex-direction: column; }
  .page-actions > *,
  .page-actions .inline-form,
  .page-actions button,
  .page-actions a { width: 100%; }
}
