html,
body {
    height: 100%;     /* Ensure html and body take full height for flex to work properly */
    margin: 0;
    font-size: 15px;  /* Reduced base font size */
    line-height: 1.4; /* Slightly tighter line height */
}

body {
    color: #2d3748;
    font-family: 'Inter', sans-serif;
    display: flex;              /* Full height flex layout */
    flex-direction: column;     /* Stacks children vertically */
    margin: 0;
    padding: 0;
}

/* Headings smaller and tighter */
h1 { font-size: 1.6em; margin: 0.5em 0; }
h2 { 
    font-size: 1.3em; 
    margin: 0.5em 0; 
}
h3 { font-size: 1.1em; margin: 0.4em 0; }
h4, h5, h6 { font-size: 1em; margin: 0.3em 0; }

/* Paragraphs and lists tighter */
p, ul, ol { margin: 0.5em 0; }
li { margin: 0.2em 0; }

/* Reduce default padding for buttons and inputs */
button, input, select, textarea {
    font-size: 0.95em;
    padding: 0.3em 0.7em;
    margin: 0.2em 0.3em;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: #f9fafb;
    transition: background 0.2s, box-shadow 0.2s;
}

/* Restore native checkbox/radio styling */
input[type="checkbox"],
input[type="radio"] {
    appearance: auto;
    -webkit-appearance: auto;
    width: auto;
    height: auto;
    padding: 0;
    background: transparent;
}

/* Compact tables and lists */
table {
    font-size: 0.95em;
    border-collapse: collapse;
}
th, td {
    padding: 0.35em 0.7em;
    line-height: 1.3;
}
tr {
    height: 1.8em;
}
ul, ol {
    padding-left: 1.2em;
}
ul li, ol li {
    margin-bottom: 0.15em;
    font-size: 0.97em;
}

button {
    cursor: pointer;
    background: #2563eb;
    color: #fff;
    border: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    font-weight: 500;
}
button:hover, button:focus {
    background: #1d4ed8;
    box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}
button:active {
    background: #1e40af;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px #bfdbfe;
}
#app-container {
    display: flex;
    flex-grow: 1;      /* app-container takes available vertical space */
    overflow: hidden;  /* Prevent app-container itself from showing scrollbars if children misbehave */
}

#sidebar {
    flex: 0 0 clamp(120px, 12vw, 200px); /* Sidebar width responsive (12% of viewport) between 120px and 200px */
    background-color: #1f2937;         /* Dark gray */
    color: white;
    gap: 0.7em;        /* Smaller gap between children */
    padding: 0.5rem;
    padding: 0.7em;    /* Reduced padding */
    display: flex;
    flex-direction: column;
    flex-shrink: 0;      /* Prevent sidebar from shrinking */
    overflow-y: auto;    /* Allow sidebar items to scroll if too many */
    font-size: 0.93em;
}

.nav-list {
    padding: 0.2em 0;
}
.nav-item {
    margin-bottom: 0.15em;
    border-bottom: 1px solid #374151;
}
.nav-item:last-child {
    border-bottom: none;
}
.nav-link {
    padding: 0.25em 0.7em;
    font-size: 0.97em;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
}
.nav-link:hover, .nav-link.active-link {
    background: #374151;
    color: #fff;
}
@media (min-width: 1440px) {
    #sidebar {
        flex-basis: 200px; /* Maximum 200px if viewport is wider than 1440px */
    }
}

#app-container.sidebar-collapsed #sidebar {
    padding: 0.5rem 0.15rem;
    font-size: 0.93em;
    width: 56px !important;
    flex-basis: 56px !important;
    min-width: 56px !important;
    max-width: 56px !important;
    transition: width 0.3s, flex-basis 0.3s, min-width 0.3s, max-width 0.3s;
}

#app-container.sidebar-collapsed .logo-text {
    display: none;
}

/* Navigation list styles */
.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;     /* rounded-md */
    color: #d1d5db;     /* gray-300 */
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease, padding 0.3s ease;
    white-space: nowrap;     /* Prevent text wrapping */
}

/* Navigation icon and label styling */
.nav-icon {
    display: flex;
    align-items: center;
    margin-right: 0.75rem;
    flex-shrink: 0;
    transition: margin-right 0.3s ease;
}

.nav-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

.nav-label {
    flex: 1;
    transition: opacity 0.3s ease, visibility 0.3s ease, max-width 0.3s ease, flex-basis 0.3s ease, width 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    opacity: 1;
    visibility: visible;
    max-width: 100%;
    width: auto;
    overflow: hidden;
}

.nav-link:hover,
.nav-link.active-link {     /* We'll need JS to set .active-link */
    background-color: #374151;     /* gray-700 */
    color: white;
}

#app-container.sidebar-collapsed .nav-item a {
    justify-content: center;     /* Center icon */
}

#app-container.sidebar-collapsed .nav-label {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    width: 0;
    flex: 0 0 0;
    margin: 0;
    padding: 0;
}

#app-container.sidebar-collapsed .auth-status-container {
    opacity: 0;
    height: 0;
    overflow: hidden;
    margin-bottom: 0;
    padding: 0;
}

/* Ensure icons are properly sized and centered when collapsed */
#app-container.sidebar-collapsed .nav-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 0;
}

/* Adjust padding when collapsed to center icons better */
#app-container.sidebar-collapsed .nav-link {
    padding: 0.45rem;
    justify-content: center;
    width: 100%;
}

#sidebar-toggle-button {
    margin-left: auto;
    transition: margin-left 0.3s ease;
}

#app-container.sidebar-collapsed #sidebar-toggle-button {
    margin-left: 0;
}

.user-profile-section {
    margin-top: auto;     /* Pushes to the bottom */
    padding-top: 1rem;
    border-top: 1px solid #374151;     /* gray-700 */
    flex-shrink: 0;     /* Prevent user profile from shrinking */
}

/* Main content area */
#main-content-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;         /* Main content takes available horizontal space next to sidebar */
    overflow-y: auto;     /* Crucial: main content scrolls internally */
    background-color: #f7fafc;
}

/* Global loading indicator overlay used by htmx (hx-indicator) */
#loading-indicator {
    display: none;    /* htmx toggles this by adding .htmx-request to the element */
    position: fixed;
    inset: 0;         /* cover viewport */
    z-index: 1000;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.3); /* subtle white veil */
}
#loading-indicator.htmx-request {
    display: flex;
}

/* Error toast overlay - blocks interaction when error toast is visible */
#error-toast-overlay {
    display: none;
    position: fixed;
    inset: 0;             /* cover viewport */
    z-index: 999;         /* Just below the toast (z-index: 1000) */
    background: rgba(0, 0, 0, 0.35); /* subtle dark veil */
    pointer-events: auto; /* Block all interactions */
}

#error-toast-overlay.active {
    display: block;
}

.scrollable-table {
    max-height: 400px;
    overflow-y: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 0.375rem;
}

#data-display {
    flex: 1 0 auto;  /* Grow to fill space, don't shrink, auto basis */
    margin: 1rem 1rem 0.5rem 1rem;   /* top right bottom left - matches original parent padding */
    background-color: #ffffff;
    border-radius: 0.5rem;  /* rounded-lg */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06); /* shadow */
    padding: 0.25rem 1.5rem 1.5rem 1.5rem; /* top right bottom left */
    box-sizing: border-box;
}

#main-content-area header h1 {
    color: #2563eb;      /* blue-600 */
    font-size: 2.25rem;    /* text-4xl */
    line-height: 2.5rem;   /* leading-tight-ish */
    font-weight: 700;      /* font-bold */
    margin-bottom: 0.5rem; /* mb-2 */
}

.auth-ok {
    color: #34d399;   /* emerald-400 */
    font-weight: 500;   /* font-medium */
    font-size: 0.75rem; /* text-xs */
}

.auth-warn {
    color: #f87171;   /* red-400 */
    font-weight: 500;   /* font-medium */
    font-size: 0.75rem; /* text-xs */
}

.auth-status-container {
    display: flex;
    flex-direction: column;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
    transition: opacity 0.6s ease-in-out, height 0.3s ease-in-out, margin-bottom 0.3s ease-in-out, padding 0.3s ease-in-out;
}

.user-email-display {
    font-size: 0.75rem; /* text-xs */
    color: #d1d5db;   /* gray-300 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* truncate */
}

.logo-text {
    font-size: 1.25rem; /* text-xl */
    font-weight: 600;   /* font-semibold */
}

#loading-indicator p {
    font-size: 1.125rem; /* text-lg */
    font-weight: 600;    /* font-semibold */
    color: #2563eb;    /* blue-600 */
}

/* Loading UI sizes/colors matching old Tailwind */
#sidebar-navigation .loading-text {
    font-size: 0.875rem; /* text-sm */
    color: #9ca3af;    /* gray-400 */
}

.content-loading {
    text-align: center; /* text-center */
    padding-top: 3rem;  /* py-12 */
    padding-bottom: 3rem;
    color: #6b7280;  /* gray-500 */
}

/* Minimal size helpers for server-rendered icons */
.w-4 { width: 1rem; }
.h-4 { height: 1rem; }
.w-5 { width: 1.25rem; }
.h-5 { height: 1.25rem; }
.w-6 { width: 1.5rem; }
.h-6 { height: 1.5rem; }
.w-8 { width: 2rem; }
.h-8 { height: 2rem; }
.w-10 { width: 2.5rem; }
.h-10 { height: 2.5rem; }
.w-12 { width: 3rem; }
.h-12 { height: 3rem; }

/* Main content container */
#main-content {
    display: flex;
    flex-direction: column;
    width: 100%; /* needed for percentage-based child widths */
    box-sizing: border-box;
}

/* Form page container - centered form layout for create/edit screens */
.form-page-container {
    width: 80%;
    margin: 0 auto;
}

/* Default SVG sizing in main content to prevent oversized icons */
#main-content svg {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-block;
    vertical-align: middle;
}

/* ===== COMMON COMPONENT STYLES ===== */

/* Layout Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    background: #f8fafc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 1.5px 4px rgba(0,0,0,0.04);
    border: 1px solid #e5e7eb;
}

.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
}

.grid-3-col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

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

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

/* Card/Section Styles */
.card {
    background: #f8fafc;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    margin-bottom: 1.1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 1.5px 4px rgba(0,0,0,0.04);
}

.card-light {
    background: #f3f4f6;
    padding: 1.1rem;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    margin-bottom: 1rem;
    box-shadow: 0 1.5px 6px rgba(0,0,0,0.04);
}

/* Typography Helpers */
.text-muted {
    color: #6c757d;
}

.text-primary {
    color: #007bff;
}

.text-secondary {
    color: #495057;
}

.text-danger {
    color: #dc3545;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

.text-sm {
    font-size: 0.9rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-uppercase {
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Spacing Utilities */
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.mb-3 { margin-bottom: 1.1rem; }
.mb-4 { margin-bottom: 1.6rem; }

/* Interactive Elements */
.p-3 { padding: 1.2rem; }
.p-4 { padding: 1.6rem; }

.clickable:hover {
    background: #e9ecef;
    border-radius: 4px;
}

/* No Data States */
.no-data {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
    font-style: italic;
}

/* === UI improvements for detail pages === */
.subsection-title {
    margin: 0 0 0.25rem 0;
    color: #495057;
    font-weight: 600;
}

.section-divider {
    border-top: 1px solid #e9ecef;
    margin: 0.5rem 0;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.8em;
    border-radius: 12px;
    background: #e0e7ff;
    color: #3730a3;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    word-break: break-all;
}

/* Three-column definition list for label/value grids */
.dl-3 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem 1rem;
}

.dl-3 dt {
    grid-column: span 1;
    color: #495057;
    font-weight: 600;
    margin: 0;
}

.dl-3 dd {
    grid-column: span 4;
    margin: 0;
}

@media (max-width: 768px) {
    .dl-3 { grid-template-columns: 1fr; }
    .dl-3 dt, .dl-3 dd { grid-column: auto; }
}

/* Home page view */
.dashboard-links {
    margin-top: 20px;
}

.dashboard-links .mb-2 {
    border: 1px solid #000000;
    border-radius: 5px;
    padding: 12px;
    margin-bottom: 0.75rem;
}

.dashboard-links .main-resources:hover {
    background-color: #e2eafc;
}

.dashboard-links a {
    display: flex;
    text-decoration: none;
}

.dashboard-links a span.title {
    font-weight: bold;
    padding-left: 10px;
}

.dashboard-links .dashboard-link-description {
    padding-top: 10px;
}

.home-dashboard .dashboard-link-description {
    line-height: 1.3;
}

.home-dashboard .dashboard-header .subtitle { 
    font-size: 0.8rem; 
}

.home-dashboard hr { 
    margin: 0.5rem 0;
 }

.tutorials .grid-3-col {
    row-gap: 0.25rem;
}

.tutorials a span.title {
    font-size: 18px;
    font-weight: normal;
}

.subscription-action-info-box {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.subscription-action-info-box .info-box-item {
    display: flex;
    margin-top: 0.25rem;
}

.subscription-action-info-box .info-box-item>b {
    margin: 0 0.5rem;
    color: #000000;
}

.subscription-action-info-box .info-box-item>a {
    text-decoration: none;
    color: #007bff;
    margin-left: 0.25rem;
}

.home-dashboard .tutorials h3 {
    margin: 0 0 0.25rem;
    font-size: 1.0rem;
    font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  body {
    background: #1e293b;
    color: #f1f5f9;
  }
  #sidebar {
    background: #283548;
    color: #f1f5f9;
    border-right: 1px solid #475569;
  }
  header, .header {
    background: #283548;
    color: #f1f5f9;
    border-bottom: 1px solid #475569;
  }
  #main-content-area {
    background: #1e293b;
  }
  #data-display {
    background: #2d3748;
    border: 1px solid #475569;
  }
  .container, .card {
    background: #2d3748;
    color: #f1f5f9;
    border: 1px solid #475569;
    box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  }
  .card-light {
    background: #374151;
    color: #f8fafc;
    border: 1px solid #475569;
  }
  table {
    background: #2d3748;
    color: #f1f5f9;
  }
  /* Pico.css striped table override for better contrast */
  table.striped tbody tr:nth-child(odd) {
    background: #374151;
  }
  th, td {
    border-color: #475569;
  }
  button {
    background: #475569;
    color: #f1f5f9;
  }
  button:hover, button:focus {
    background: #6366f1;
    color: #fff;
  }
  input, select, textarea {
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #475569;
  }
  .badge {
    background: #475569;
    color: #93c5fd;
    box-shadow: 0 1px 6px rgba(0,0,0,0.25);
  }
  .section-divider {
    border-top: 1px solid #475569;
  }
  h1, h2, h3, h4, h5, h6 {
    color: #e2e8f0;
    font-weight: 700;
    text-shadow: none;
  }
  a {
    color: #93c5fd;
  }
  a:hover {
    color: #bfdbfe;
  }
  .dashboard-links .mb-2 {
    border-color: #475569;
  }
  .dashboard-links .main-resources:hover {
    background-color: #374151;
  }
  /* Typography helpers */
  .text-secondary {
    color: #e2e8f0;
  }
  .text-muted {
    color: #b8c0cc;
  }
  .subsection-title {
    color: #e2e8f0;
  }
  .dl-3 dt {
    color: #e2e8f0;
  }
  .dl-3 dd {
    color: #f1f5f9;
  }
  .no-data {
    color: #b8c0cc;
  }
  .content-loading {
    color: #b8c0cc;
  }
  /* Interactive elements */
  .clickable:hover {
    background: #475569;
  }
  /* Info boxes */
  .subscription-action-info-box {
    color: #b8c0cc;
  }
  .subscription-action-info-box .info-box-item > b {
    color: #f1f5f9;
  }
  .subscription-action-info-box .info-box-item > a {
    color: #93c5fd;
  }
}