/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 280px;
  --header-h: 48px;
  --bg: #ffffff;
  --bg-sidebar: #f7f8fa;
  --bg-sidebar-hover: #eef0f3;
  --bg-sidebar-active: #e1e8ff;
  --border: #e1e4e8;
  --text: #24292f;
  --text-muted: #57606a;
  --text-nav: #444d56;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --code-bg: #f6f8fa;
  --table-border: #d0d7de;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* ---- Mobile header ---- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 200;
}
.mobile-header .mobile-title {
  font-weight: 600;
  font-size: 15px;
}
#menu-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--radius);
}
#menu-toggle:hover { background: var(--bg-sidebar-hover); }

/* ---- Layout ---- */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 10;
}

.sidebar-logo {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

#search {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-muted); }

#nav {
  flex: 1;
  padding: 8px 0 24px;
  overflow-y: auto;
}

.nav-list {
  list-style: none;
  padding: 0;
}

/* Category headers */
.nav-category {
  padding: 14px 14px 4px;
}
.nav-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 4px 0;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-category-header:hover { color: var(--text); }
.nav-category-header .chevron {
  transition: transform 0.2s;
  font-size: 10px;
}
.nav-category.collapsed .chevron { transform: rotate(-90deg); }
.nav-category.collapsed .nav-ops { display: none; }

.nav-ops {
  list-style: none;
  padding: 2px 0;
}

/* Nav links */
.nav-link {
  display: block;
  padding: 5px 14px 5px 20px;
  font-size: 13px;
  color: var(--text-nav);
  text-decoration: none;
  border-radius: 0;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text);
}
.nav-link.active {
  background: var(--bg-sidebar-active);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
.nav-home {
  padding-left: 14px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

/* Hidden by search */
.nav-ops li.hidden { display: none; }
.nav-category.all-hidden { display: none; }

/* ---- Main content ---- */
main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.doc-body {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

.loading {
  color: var(--text-muted);
  font-size: 14px;
  padding: 60px 0;
  text-align: center;
}

.error-msg {
  background: #fff8f8;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 16px 20px;
  color: #b91c1c;
  font-size: 14px;
}

/* ---- Markdown content typography ---- */
.doc-body h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 10px;
  color: var(--text);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.doc-body h2 {
  font-size: 20px;
  font-weight: 600;
  margin-top: 36px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.doc-body h3 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}
.doc-body h4 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 18px;
  margin-bottom: 6px;
}

.doc-body p {
  margin-bottom: 14px;
  color: var(--text);
}

.doc-body ul, .doc-body ol {
  margin: 8px 0 14px 22px;
}
.doc-body li { margin-bottom: 4px; }

.doc-body a {
  color: var(--accent);
  text-decoration: none;
}
.doc-body a:hover { text-decoration: underline; }

/* Inline code */
.doc-body :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: #e8315a;
}

/* Code blocks */
.doc-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 16px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}
.doc-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Tables */
.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.doc-body table thead th {
  background: var(--code-bg);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--table-border);
  color: var(--text);
}
.doc-body table tbody td {
  padding: 7px 12px;
  border: 1px solid var(--table-border);
  vertical-align: top;
}
.doc-body table tbody tr:nth-child(even) {
  background: #f9fafb;
}

/* Blockquotes */
.doc-body blockquote {
  border-left: 4px solid var(--accent);
  margin: 16px 0;
  padding: 8px 16px;
  background: #f0f5ff;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}
.doc-body blockquote p { margin-bottom: 0; }

/* hr */
.doc-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

/* ---- Overview page ---- */
.overview-header {
  margin-bottom: 32px;
}
.overview-header h1 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 10px;
}
.overview-header p { color: var(--text-muted); font-size: 15px; }

.overview-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 24px 0;
}
.stat-card {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 120px;
  text-align: center;
}
.stat-card .stat-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.category-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--bg);
  transition: box-shadow 0.15s;
}
.category-card:hover { box-shadow: var(--shadow); }
.category-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}
.category-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.category-card ul li {
  margin-bottom: 2px;
}
.category-card ul li a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.category-card ul li a:hover { text-decoration: underline; }

/* ---- Types list on overview ---- */
.types-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  columns: 3;
  column-gap: 24px;
}
.types-list li {
  margin-bottom: 4px;
  break-inside: avoid;
}
.types-list li a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-mono);
}
.types-list li a:hover { text-decoration: underline; }

@media (max-width: 600px) {
  .types-list { columns: 2; }
}

/* ---- Parent group (Amazon SES / End User Messaging) in sidebar ---- */
.nav-group {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 2px;
}
.nav-group.all-hidden { display: none; }
.nav-group.collapsed .nav-group-services { display: none; }

.nav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 14px 6px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.nav-group-header:hover { background: var(--bg-sidebar-hover); }
.nav-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.nav-group-header .chevron {
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.nav-group.collapsed .nav-group-header .chevron { transform: rotate(-90deg); }

.nav-group-services {
  list-style: none;
  padding: 0;
}

/* ---- Service groups in sidebar ---- */
.nav-service-group {
  border-top: 1px solid var(--border);
  padding-top: 4px;
  margin-top: 4px;
}
.nav-service-group.all-hidden { display: none; }
.nav-service-group.collapsed .nav-service-ops { display: none; }

.nav-service-header {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 14px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
  transition: background 0.1s;
}
.nav-service-header:hover { background: var(--bg-sidebar-hover); }

.nav-service-header .service-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.nav-service-header .service-name:hover { text-decoration: underline; }
.nav-service-header .chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.nav-service-group.collapsed .nav-service-header .chevron { transform: rotate(-90deg); }

.nav-service-ops {
  list-style: none;
  padding: 0;
}

/* ---- Service color pills ---- */
.service-label,
.service-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
  line-height: 1.4;
}
.doc-body .service-badge {
  margin-bottom: 12px;
  font-size: 11px;
  padding: 3px 8px;
}

/* ---- Homepage service group sections ---- */
.service-group-section {
  margin-bottom: 36px;
}
.service-group-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ---- Homepage service cards grid ---- */
.service-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 24px;
}
.service-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  background: var(--bg);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}
.service-card:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,.1);
  transform: translateY(-1px);
}
.service-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.service-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.service-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}
.service-card-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.service-card-stats span::before {
  content: '• ';
  color: var(--border);
}
.service-card-stats span:first-child::before { content: ''; }
.service-card a {
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.service-card a:hover { text-decoration: underline; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .layout { padding-top: var(--header-h); height: calc(100vh - var(--header-h)); }

  #sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 150;
    box-shadow: 2px 0 8px rgba(0,0,0,.12);
  }
  #sidebar.open { transform: translateX(0); }

  .doc-body { padding: 24px 18px 60px; }
  .category-grid { grid-template-columns: 1fr; }
}
