/* Design tokens */
:root {
    --dsm-danger:        #cc0000;
    --dsm-success:       #2b8a3e;
    --dsm-muted:         #6b7280;
    --dsm-border:        #d1d5db;
    --dsm-border-radius: 4px;
    --dsm-mono:          ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
    --dsm-card-bg:       #f9fafb;
    --dsm-code-bg:       #f3f4f6;
    --dsm-sidebar-width: 200px;
    --dsm-sidebar-bg:    #1a202c;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; color: #111; background: #fff; }
a { color: #0066cc; }
code, pre { font-family: var(--dsm-mono); background: var(--dsm-code-bg); }
code { padding: 0.1em 0.3em; border-radius: var(--dsm-border-radius); font-size: 0.875em; }
pre { padding: 1rem; border-radius: var(--dsm-border-radius); overflow-x: auto; }
dl dt { font-weight: bold; margin-top: 0.75rem; }
dl dd { margin: 0.25rem 0 0 0; }

/* ── Side-menu layout ─────────────────────────────────────────────────────── */

#layout, #menu, .menu-link {
    -webkit-transition: all 0.2s ease-out;
    transition: all 0.2s ease-out;
}

#layout {
    position: relative;
    left: 0;
    padding-left: 0;
}

/* When menu is open on mobile, push content right */
#layout.active #menu  { left: var(--dsm-sidebar-width); width: var(--dsm-sidebar-width); }
#layout.active .menu-link { left: var(--dsm-sidebar-width); }

/* Sidebar */
#menu {
    margin-left: calc(-1 * var(--dsm-sidebar-width));
    width: var(--dsm-sidebar-width);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    background: var(--dsm-sidebar-bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#menu .pure-menu { flex: 1; }

.dsm-brand {
    display: block;
    color: #fff !important;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 1rem;
    line-height: 1.3;
    white-space: normal;
    text-transform: none;
    letter-spacing: 0;
}

#menu .pure-menu-list { border-top: 1px solid #2d3748; }
#menu .pure-menu ul, #menu .pure-menu { border: none; background: transparent; }
#menu .pure-menu-link { color: #a0aec0; padding: 0.65rem 1rem; font-size: 0.9rem; }
#menu .pure-menu-link:hover,
#menu .pure-menu-link:focus { color: #fff; background: #2d3748; }
#menu .pure-menu-selected > .pure-menu-link { color: #fff; background: #2b6cb0; }

/* Sidebar footer: user email + logout */
.dsm-sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid #2d3748;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.dsm-nav-email { color: #718096; font-size: 0.8rem; word-break: break-all; }

/* Hamburger button */
.menu-link {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    top: 0; left: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10;
    width: 44px;
    height: 44px;
    text-decoration: none;
}
.menu-link:hover, .menu-link:focus { background: #000; }

/* ── Container ────────────────────────────────────────────────────────────── */
.dsm-container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 2rem; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.dsm-card { background: var(--dsm-card-bg); border: 1px solid var(--dsm-border); border-radius: var(--dsm-border-radius); padding: 1.25rem; margin-bottom: 1rem; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; gap: 0.75rem; }
.page-header > div { margin: 0; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 1rem; }
.pure-table { width: 100%; }
.pure-table th, .pure-table td { padding: 0.6rem 0.75rem; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.pure-button { border-radius: var(--dsm-border-radius); cursor: pointer; }
.btn-small { padding: 0.25rem 0.5rem !important; font-size: 0.875rem; margin: 0; }
.btn-secondary { background: #6b7280; color: #fff; border: 1px solid #6b7280; }
.btn-secondary:hover, .btn-secondary:focus { background: #4b5563; border-color: #4b5563; color: #fff; }
.btn-danger { background: var(--dsm-danger); color: #fff; border: 1px solid var(--dsm-danger); }
.btn-danger:hover, .btn-danger:focus { background: #a00; border-color: #a00; color: #fff; }

/* ── Nav form ─────────────────────────────────────────────────────────────── */
.nav-form { margin: 0; display: inline; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash { padding: 0.75rem 1rem; margin-bottom: 1rem; border-radius: var(--dsm-border-radius); border: 1px solid; border-left-width: 4px; }
.flash-success { border-color: var(--dsm-success); color: var(--dsm-success); background: var(--dsm-card-bg); }
.flash-error { border-color: var(--dsm-danger); color: var(--dsm-danger); background: var(--dsm-card-bg); }

/* ── Status badges ────────────────────────────────────────────────────────── */
.status-active { color: var(--dsm-success); font-weight: bold; }
.status-inactive { color: var(--dsm-muted); }

/* ── Env reveal ───────────────────────────────────────────────────────────── */
.env-content { white-space: pre-wrap; word-break: break-all; font-family: var(--dsm-mono); font-size: 0.875rem; }
.env-masked { filter: blur(4px); user-select: none; }

/* ── Form actions row ─────────────────────────────────────────────────────── */
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; align-items: center; }
.form-actions button, .form-actions .pure-button { margin: 0; }

/* ── Checkbox hint ────────────────────────────────────────────────────────── */
.checkbox-hint { display: block; margin-top: 0.25rem; margin-left: 1.75rem; color: var(--dsm-muted); font-size: 0.875rem; }

/* ── Pure form adjustments ────────────────────────────────────────────────── */
.pure-form input[type="text"],
.pure-form input[type="email"],
.pure-form input[type="password"],
.pure-form input[type="date"],
.pure-form select,
.pure-form textarea {
    width: 100%;
    border: 1px solid var(--dsm-border);
    border-radius: var(--dsm-border-radius);
    padding: 0.5rem 0.6rem;
    font-size: 1rem;
    margin-top: 0.25rem;
}
.pure-form label { font-weight: 500; margin-top: 0.75rem; display: block; }
.pure-form small { display: block; color: var(--dsm-muted); font-size: 0.85rem; margin-top: 0.2rem; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-container { max-width: 480px; margin: 2rem auto; }

/* ── Inline form ──────────────────────────────────────────────────────────── */
.inline-form { display: inline; margin: 0; }

/* ── Table actions ────────────────────────────────────────────────────────── */
.table-actions { display: flex; align-items: stretch; gap: 0.375rem; flex-wrap: nowrap; }
.table-actions .inline-form { display: contents; }
.table-actions a.pure-button, .table-actions button { display: flex; align-items: center; justify-content: center; margin: 0; white-space: nowrap; }

/* ── Stats card row ───────────────────────────────────────────────────────── */
.dsm-stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.dsm-stat { flex: 1; min-width: 200px; }
.dsm-stat .dsm-stat-value { font-size: 2rem; font-weight: bold; margin: 0.5rem 0; }
.dsm-stat .dsm-stat-label { color: var(--dsm-muted); font-size: 0.875rem; }

/* ── Token display ────────────────────────────────────────────────────────── */
.token-display { background: var(--dsm-code-bg); padding: 1rem; border-radius: var(--dsm-border-radius); word-break: break-all; font-family: var(--dsm-mono); }

/* ── Page title ───────────────────────────────────────────────────────────── */
.dsm-page-title { margin-bottom: 1rem; }
.dsm-page-title h2 { margin: 0 0 0.25rem; }
.dsm-page-title p { margin: 0; color: var(--dsm-muted); }

/* ── Muted text ───────────────────────────────────────────────────────────── */
.muted { color: var(--dsm-muted); }

/* ── Responsive ───────────────────────────────────────────────────────────── */

/* Desktop: sidebar always visible, hamburger hidden */
@media (min-width: 48em) {
    #layout { padding-left: var(--dsm-sidebar-width); }
    #menu { left: var(--dsm-sidebar-width); }
    .menu-link { display: none; }
    #layout.active .menu-link { left: var(--dsm-sidebar-width); }
}

/* Mobile: sidebar slides in over content */
@media (max-width: 48em) {
    #layout.active { position: relative; left: var(--dsm-sidebar-width); }
    .table-wrapper table { min-width: 480px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions button, .form-actions .pure-button { text-align: center; width: 100%; }
    table { font-size: 0.875rem; }
    td code { word-break: break-all; font-size: 0.8rem; }
    .dsm-container { padding: 1rem; }
}
