/* ===================
   LAYOUT.CSS
   Structure only - no colors
   =================== */


/* ===================
   BASE / TYPOGRAPHY
   =================== */

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-page);
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
}

h1 { font-size: 1.75rem; margin: 0 0 1rem 0; text-align: center; font-weight: 600; }
h2 { font-size: 1.25rem; margin: 0 0 0.75rem 0; font-weight: 600; }
h3 { font-size: 1rem; margin: 0 0 0.5rem 0; font-weight: 600; }

p { margin: 0 0 0.5rem 0; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.text-xs { font-size: 0.75rem; }
.text-small { font-size: 0.875rem; }
.text-large { font-size: 1.5rem; }
.text-xlarge { font-size: 2rem; font-weight: 600; }

.text-bold { font-weight: 600; }
.text-italic { font-style: italic; }
.text-center { text-align: center; }
.center { text-align: center; }


/* ===================
   PAGE STRUCTURE
   =================== */

.content-centered {
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
    padding: 1rem;
}

.narrow { max-width: 600px; margin: 0 auto; }
.max-80 { max-width: 80%; }


/* ===================
   NAVBAR
   =================== */

.sticky-top {
    position: sticky;
    top: 0;
    z-index: 200;
}

.mini-chart {
    width: 100px;
    height: 36px;
    background: var(--neutral-light);
    border-radius: 4px;
    overflow: hidden;
}

.justify-between {
    justify-content: space-between;
}

.padding-x-1 {
    padding: 0 1rem;
}

.pulldown {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 1rem;
    width: 400px;
    max-width: 90vw;
    z-index: 300;
}


/* ===================
   VIDEO
   =================== */

.video {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.video iframe,
.video video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}


/* ===================
   BOXES
   =================== */

.box {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}


/* ===================
   SPACING
   =================== */

.spacer { margin-top: 2rem; }
.spacer-small { margin-top: 1rem; }

.scroll-container {
    max-height: 70vh;
    overflow-y: auto;
}


/* ===================
   TABLES
   =================== */

table {
    margin: 0 auto;
    border-collapse: collapse;
}

table th,
table td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    vertical-align: top;
}

table.grid td:not(:first-child),
table.grid th:not(:first-child) {
    text-align: center;
}


/* ===================
   GRID
   =================== */

.two-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.three-column {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

.four-column {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .two-column,
    .three-column,
    .four-column {
        grid-template-columns: 1fr;
    }
}


/* ===================
   ROWS (flex containers)
   =================== */

.row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.row > * {
    flex-shrink: 0;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
}

.row-gap-1 { gap: 1rem; }


/* ===================
   ALIGNMENT
   =================== */

.align-right {
    display: flex;
    justify-content: flex-end;
}

.align-center {
    display: flex;
    justify-content: center;
}


/* ===================
   UTILITIES
   =================== */

.bg-card { background: var(--bg-card); }
.bg-white { background: var(--white); }

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

.arrow {
    transition: transform 0.2s;
}

.open .arrow {
    transform: rotate(180deg);
}

.hidden { display: none; }


/* ===================
   EXPANDABLE (accordions, dropdowns)
   =================== */

.expandable {
    cursor: pointer;
}

.expandable-content {
    display: none;
    padding-top: 1rem;
}

.expandable.open .expandable-content {
    display: block;
}


/* ===================
   MODALS
   =================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    width: min(560px, 100%);
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    border: 1px solid var(--border);
    box-shadow: 0 18px 60px rgba(0,0,0,0.25);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
}

/* results list inside modals */
.modal-results {
    max-height: 320px;
    overflow-y: auto;
}

.modal-result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.modal-result-row:last-child { border-bottom: none; }


/* ===================
   TOASTS
   =================== */

.toast {
    position: fixed;
    left: 50%;
    bottom: 2rem;
    transform: translateX(-50%);
    z-index: 1001;
    display: none;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    background: var(--toast-bg);
    color: var(--toast-text);
}


/* ===================
   SELECTABLE
   =================== */

.selectable {
    cursor: pointer;
}

.selectable.selected {
    border: 2px solid var(--selected);
}


/* ===================
   BUTTONS
   =================== */

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    opacity: 0.9;
    text-decoration: none;
}

.btn:disabled {
    background: var(--neutral);
    cursor: not-allowed;
    opacity: 1;
}


/* ===================
   PILLS
   =================== */

.pill {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border: none;
    border-radius: 999px;
    font-family: var(--font);
    font-size: 0.875rem;
    white-space: nowrap;
}


/* ===================
   BADGES
   =================== */

.badge {
    display: inline-block;
    min-width: 1.25rem;
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    color: var(--white);
    background: var(--danger);
}


/* ===================
   FORMS
   =================== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 1rem;
    background: var(--bg-card);
    color: var(--text);
    box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(54, 162, 235, 0.1);
}

textarea {
    width: 100%;
    min-height: 100px;
    resize: vertical;
}


/* ===================
   PROGRESS BAR
   =================== */

.progress-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--neutral-light);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
}


/* ===================
   SETTINGS PAGE ONLY
   =================== */

.color-swatches {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.gradient-bar {
    height: 8px;
    margin-top: 0.5rem;
    border-radius: 4px;
    background: linear-gradient(to right, var(--safe), var(--caution), var(--danger));
}

.font-preview { margin-top: 0.5rem; }
.font-default { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.font-serif { font-family: Georgia, "Times New Roman", Times, serif; }
.font-rounded { font-family: "Nunito", "Varela Round", sans-serif; }

[data-font="serif"] { font-family: Georgia, "Times New Roman", Times, serif; }
[data-font="rounded"] { font-family: "Nunito", "Varela Round", sans-serif; }


/* ===================
   EXERCISE LAYOUTS
   Two-column layout with sidebar
   =================== */

.exercise-layout {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

.exercise-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.exercise-main .scroll-container {
  flex: 1;
  min-height: 0;
}

.exercise-sidebar {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

@media (max-width: 900px) {
    .exercise-layout {
        flex-direction: column;
    }
    
    .exercise-sidebar {
        width: 100%;
        position: relative;
        top: 0;
        max-height: none;
        order: -1;
        margin-bottom: 1rem;
    }
}

/* Exercise actions: keep buttons aligned to the left of the main column */
.exercise-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-top: 1rem;
}

/* If any legacy wrapper is centering buttons, override it inside exercise pages */
.exercise-main .center,
.exercise-main .text-center {
  text-align: left;
}

/* Tools page: stack the three tool sections with spacing */
.tools-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Tools page: each table scrolls independently */
.tools-section .scroll-container {
  max-height: 35vh;
  overflow-y: auto;
}

/* ===================
   ADDITIONS FOR TOOLS REPORT
   Add these to the END of layout.css
   =================== */


/* ===================
   DETAILS CARDS (expandable)
   Used for tool ranking cards
   =================== */

details.details-card {
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    margin-bottom: 0.75rem;
    overflow: hidden;
}

/* When combined with .safe/.caution/.danger from themes.css, use --color for left border */
details.details-card.safe,
details.details-card.caution,
details.details-card.danger {
    border-left-color: var(--color);
}

.details-summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    list-style: none;
    background: var(--neutral-light);
}

.details-summary::-webkit-details-marker {
    display: none;
}

.details-summary .text-bold {
    color: var(--link);
}

details.details-card[open] .arrow {
    transform: rotate(180deg);
}

.details-body {
    padding: 1rem;
    border-top: 1px solid var(--border);
}


/* ===================
   BOX VARIANTS
   =================== */

.box-soft {
    background: var(--neutral-light);
    border: none;
}


/* ===================
   EFFECTIVENESS BAR
   Mini stacked bar for tool summaries
   =================== */

.effectiveness-bar {
    width: 80px;
    height: 8px;
    border-radius: 4px;
    background: var(--neutral-light);
    overflow: hidden;
    display: flex;
}

.effectiveness-bar-segment {
    height: 100%;
    min-width: 0;
}

.effectiveness-bar-segment.safe {
    background: var(--safe);
}

.effectiveness-bar-segment.caution {
    background: var(--caution);
}

.effectiveness-bar-segment.danger {
    background: var(--danger);
}

/* ===================
   EVENT CARDS
   For usage history items
   =================== */

.event-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.event-card.current {
    border-color: var(--caution);
    box-shadow: 0 0 0 2px var(--caution-light);
}

/* ===================
   ADDITIONS FOR TOOLS_ADD PAGE
   Add to END of layout.css
   =================== */


/* ===================
   TABS
   Horizontal tab navigation
   =================== */

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    color: var(--text-muted);
}

.tab:hover {
    color: var(--text);
    text-decoration: none;
}

.tab.active {
    font-weight: 600;
    border-bottom-color: currentColor;
}

.tab.active.mania {
    color: var(--mania);
}

.tab.active.depression {
    color: var(--depression);
}


/* ===================
   FORM INPUT FULL WIDTH
   Make inputs/selects fill container
   =================== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
}


/* ===================
   ROW WITH FLEX INPUT
   For search forms where input should grow
   =================== */

.row input[type="text"] {
    flex: 1;
    min-width: 0;
}

/* ===================
   FORM GROUPS
   Vertical spacing for form fields
   =================== */

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
}

/* In narrow/centered forms, don't force full width on selects */
.narrow select,
.narrow input[type="text"],
.narrow input[type="email"],
.narrow input[type="password"],
.narrow input[type="number"] {
    width: auto;
    min-width: 200px;
}


/* ===================
   BUTTON SIZES
   =================== */

.btn-large {
    padding: 0.875rem 2rem;
    font-size: 1.125rem;
    border-radius: 10px;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.legend-badge {
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Chart container - required for Chart.js sizing */
.chart-container {
    position: relative;
    height: 500px;
    width: 100%;
}

.graph-box {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.timeline-marker-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--danger);
    opacity: 0.7;
    z-index: 15;
    pointer-events: none;
}

.row-wrap { flex-wrap: wrap; }
.row-center { justify-content: center; }


/* ===================
   INLINE LINK BUTTON
   Looks like a text link, works as a button
   =================== */

.btn-link {
    background: none;
    border: none;
    color: var(--link);
    padding: 0.125rem 0.25rem;
    font-size: 0.875rem;
    font-family: var(--font);
    cursor: pointer;
    text-decoration: none;
}

.btn-link:hover {
    color: var(--link);
    text-decoration: underline;
    background: none;
}

.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { color: var(--critical); }

.btn-link.safe { color: var(--safe); }
.btn-link.safe:hover { text-decoration: underline; }


/* ===================
   INLINE FORM
   Display form inline (for action buttons in tables)
   =================== */

.inline {
    display: inline;
}