/* CI Build Monitor - Common Styles
 * Tailwind-inspired utility classes + component styles
 */

/* ============================================================
   CSS Variables (Design Tokens)
   ============================================================ */
:root {
    /* Colors - Dark theme with better contrast */
    --color-bg-base: #0f0f1a;
    --color-bg-surface: #1e1e32;
    --color-bg-elevated: #2a2a44;
    --color-bg-header: #161625;

    --color-border: #4a4a6a;
    --color-border-subtle: #2a2a44;

    --color-text-primary: #ffffff;
    --color-text-secondary: #e0e0e0;
    --color-text-muted: #888888;
    --color-text-faint: #666666;

    /* Status colors */
    --color-success: #4caf50;
    --color-success-hover: #45a049;
    --color-success-bg: rgba(76, 175, 80, 0.2);

    --color-danger: #f44336;
    --color-danger-hover: #d32f2f;
    --color-danger-bg: rgba(244, 67, 54, 0.2);

    --color-warning: #ff9800;
    --color-warning-bg: rgba(255, 152, 0, 0.2);

    --color-info: #64b5f6;

    /* Provider colors */
    --color-sourcehut: #ffcc00;
    --color-sourcehut-text: #000000;
    --color-github: #238636;
    --color-gitlab: #fc6d26;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    /* Font sizes */
    --text-xs: 10px;
    --text-sm: 12px;
    --text-base: 14px;
    --text-lg: 16px;
    --text-xl: 18px;
    --text-2xl: 24px;

    /* Border radius */
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-xl: 8px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;

    /* Layout */
    --max-width-sm: 300px;
    --max-width-md: 500px;
    --max-width-lg: 700px;
    --max-width-xl: 800px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: var(--text-base);
    background: var(--color-bg-base);
    color: var(--color-text-secondary);
    line-height: 1.5;
}

a {
    color: var(--color-info);
    text-decoration: none;
}

a:hover {
    color: var(--color-text-primary);
}

/* ============================================================
   Layout Utilities
   ============================================================ */
.container {
    max-width: var(--max-width-md);
    margin: 0 auto;
    padding: var(--space-5);
}

.container-lg {
    max-width: var(--max-width-lg);
    margin: 0 auto;
}

.container-xl {
    max-width: var(--max-width-xl);
    margin: 0 auto;
}

/* Flexbox */
.flex {
    display: flex;
}
.flex-col {
    flex-direction: column;
}
.flex-wrap {
    flex-wrap: wrap;
}
.flex-1 {
    flex: 1;
}
.flex-shrink-0 {
    flex-shrink: 0;
}

.items-start {
    align-items: flex-start;
}
.items-center {
    align-items: center;
}
.items-end {
    align-items: flex-end;
}

.justify-start {
    justify-content: flex-start;
}
.justify-center {
    justify-content: center;
}
.justify-between {
    justify-content: space-between;
}
.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: var(--space-1);
}
.gap-2 {
    gap: var(--space-2);
}
.gap-3 {
    gap: var(--space-3);
}
.gap-4 {
    gap: var(--space-4);
}

/* Grid */
.grid {
    display: grid;
}
.grid-cols-auto {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
}

/* Spacing */
.m-0 {
    margin: 0;
}
.m-auto {
    margin: auto;
}
.mx-auto {
    margin-left: auto;
    margin-right: auto;
}
.mt-1 {
    margin-top: var(--space-1);
}
.mt-2 {
    margin-top: var(--space-2);
}
.mt-3 {
    margin-top: var(--space-3);
}
.mt-4 {
    margin-top: var(--space-4);
}
.mb-2 {
    margin-bottom: var(--space-2);
}
.mb-3 {
    margin-bottom: var(--space-3);
}
.mb-4 {
    margin-bottom: var(--space-4);
}
.ml-2 {
    margin-left: var(--space-2);
}
.ml-3 {
    margin-left: var(--space-3);
}
.ml-auto {
    margin-left: auto;
}

.p-0 {
    padding: 0;
}
.p-2 {
    padding: var(--space-2);
}
.p-3 {
    padding: var(--space-3);
}
.p-4 {
    padding: var(--space-4);
}
.p-5 {
    padding: var(--space-5);
}
.px-3 {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
}
.px-4 {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}
.py-2 {
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
}
.py-3 {
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
}

/* Width */
.w-full {
    width: 100%;
}
.min-w-0 {
    min-width: 0;
}

/* ============================================================
   Typography
   ============================================================ */
.text-xs {
    font-size: var(--text-xs);
}
.text-sm {
    font-size: var(--text-sm);
}
.text-base {
    font-size: var(--text-base);
}
.text-lg {
    font-size: var(--text-lg);
}
.text-xl {
    font-size: var(--text-xl);
}
.text-2xl {
    font-size: var(--text-2xl);
}

.font-medium {
    font-weight: 500;
}
.font-semibold {
    font-weight: 600;
}
.font-bold {
    font-weight: 700;
}

.font-mono {
    font-family: ui-monospace, monospace;
}

.text-primary {
    color: var(--color-text-primary);
}
.text-secondary {
    color: var(--color-text-secondary);
}
.text-muted {
    color: var(--color-text-muted);
}
.text-faint {
    color: var(--color-text-faint);
}
.text-success {
    color: var(--color-success);
}
.text-danger {
    color: var(--color-danger);
}
.text-warning {
    color: var(--color-warning);
}
.text-info {
    color: var(--color-info);
}

.text-center {
    text-align: center;
}
.text-right {
    text-align: right;
}
.uppercase {
    text-transform: uppercase;
}
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.whitespace-nowrap {
    white-space: nowrap;
}

/* ============================================================
   Components: Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-base);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-sm);
}

.btn-primary {
    background: var(--color-success);
    color: var(--color-text-primary);
}

.btn-primary:hover {
    background: var(--color-success-hover);
}

.btn-secondary {
    background: var(--color-border-subtle);
    color: var(--color-text-secondary);
}

.btn-secondary:hover {
    background: var(--color-bg-elevated);
}

.btn-danger {
    background: var(--color-danger);
    color: var(--color-text-primary);
}

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

.btn-group {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

/* ============================================================
   Components: Forms
   ============================================================ */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-base);
    color: var(--color-text-secondary);
    font-size: var(--text-base);
    transition: border-color var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-success);
}

select {
    cursor: pointer;
}

.help-text {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

/* ============================================================
   Components: Cards
   ============================================================ */
.card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.card:hover {
    background: var(--color-bg-elevated);
}

.card-header {
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.card-body {
    padding: var(--space-4);
}

/* ============================================================
   Components: Sections (for settings pages)
   ============================================================ */
.section {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.section h2 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--space-4);
}

.section-header {
    padding: var(--space-3) var(--space-4);
    background: var(--color-border-subtle);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.section-header.failures {
    color: var(--color-danger);
}
.section-header.passing {
    color: var(--color-success);
}

.section-content {
    padding: var(--space-3);
}

/* ============================================================
   Components: Status Indicators
   ============================================================ */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot-sm {
    width: 10px;
    height: 10px;
}

.status-ok {
    background: var(--color-success);
}
.status-failed {
    background: var(--color-danger);
}
.status-pending {
    background: var(--color-warning);
}
.status-unknown {
    background: var(--color-text-muted);
}

/* Build status icons */
.build-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: bold;
    text-decoration: none;
}

.build-icon.ok {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.build-icon.failed {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.build-icon.pending {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.build-icon:hover {
    opacity: 0.8;
}

/* ============================================================
   Components: Provider Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 9px;
    font-weight: bold;
    text-transform: uppercase;
    flex-shrink: 0;
}

.badge-sourcehut {
    background: var(--color-sourcehut);
    color: var(--color-sourcehut-text);
}

.badge-github {
    background: var(--color-github);
    color: var(--color-text-primary);
}

.badge-gitlab {
    background: var(--color-gitlab);
    color: var(--color-text-primary);
}

/* ============================================================
   Components: Lists
   ============================================================ */
.list {
    list-style: none;
}

.list-item {
    display: flex;
    align-items: center;
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--color-bg-base);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
}

.list-item:last-child {
    margin-bottom: 0;
}

/* ============================================================
   Components: Tabs
   ============================================================ */
.tabs {
    display: flex;
    justify-content: center;
    background: var(--color-bg-header);
    border-bottom: 1px solid var(--color-border-subtle);
    padding: 0 var(--space-5);
}

.tab {
    padding: var(--space-3) var(--space-5);
    cursor: pointer;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    transition: all var(--transition-base);
    font-size: var(--text-sm);
}

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

.tab.active {
    color: var(--color-success);
    border-bottom-color: var(--color-success);
}

.tab-content {
    display: none;
    padding: var(--space-5);
    max-width: var(--max-width-xl);
    margin: 0 auto;
}

.tab-content.active {
    display: block;
}

/* ============================================================
   Components: Header
   ============================================================ */
.header {
    background: var(--color-bg-header);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header h1 img {
    width: 32px;
    height: 32px;
}

/* ============================================================
   Components: Status Messages
   ============================================================ */
.status-message {
    padding: var(--space-3);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    display: none;
}

.status-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success);
    color: var(--color-success);
}

.status-error {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
}

/* ============================================================
   Components: Empty States
   ============================================================ */
.empty {
    color: var(--color-text-faint);
    font-style: italic;
    padding: var(--space-5);
    text-align: center;
}

/* ============================================================
   Components: Token Input
   ============================================================ */
.token-input-wrapper {
    position: relative;
}

.token-input {
    padding-right: 36px !important;
}

.token-toggle {
    position: absolute;
    right: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--space-1);
}

.token-toggle:hover {
    color: var(--color-text-secondary);
}

/* ============================================================
   Components: Dividers
   ============================================================ */
hr {
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    margin: var(--space-5) 0;
}

/* ============================================================
   Components: Code / Raw Data
   ============================================================ */
.code-block {
    background: #0d1117;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-family: ui-monospace, monospace;
    font-size: var(--text-sm);
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   Page-Specific: Popup
   ============================================================ */
.popup-body {
    width: 320px;
    min-height: 200px;
}

/* ============================================================
   Page-Specific: Dashboard Timeline
   ============================================================ */
.timeline-event {
    display: flex;
    align-items: flex-start;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    gap: var(--space-2);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.timeline-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.timeline-info {
    flex: 1;
    min-width: 0;
}

.timeline-title {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.timeline-detail {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.timeline-time {
    font-size: var(--text-xs);
    color: var(--color-text-faint);
    margin-left: auto;
    padding-left: var(--space-3);
    white-space: nowrap;
}

/* ============================================================
   Page-Specific: Dashboard Repo Cards
   ============================================================ */
.repo-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.repo-card:hover {
    background: var(--color-bg-elevated);
}

.repo-header {
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.repo-info {
    flex: 1;
    min-width: 0;
}

.repo-name {
    font-weight: 500;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
}

.repo-name a {
    color: var(--color-text-primary);
}

.repo-name a:hover {
    color: var(--color-info);
}

.repo-meta {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.repo-stats {
    display: flex;
    gap: var(--space-1);
    flex-shrink: 0;
}

/* ============================================================
   Utilities: Display
   ============================================================ */
.hidden {
    display: none;
}
.block {
    display: block;
}
.inline-block {
    display: inline-block;
}
.inline-flex {
    display: inline-flex;
}

/* ============================================================
   Page-Specific: Popup Status Summary
   ============================================================ */
.status-summary.all-ok {
    background: var(--color-success-bg);
}

.status-summary.all-ok .status-text {
    color: var(--color-success);
}

.status-summary.has-failures {
    background: var(--color-danger-bg);
}

.status-summary.has-failures .status-text {
    color: var(--color-danger);
}

.failure-item {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-danger);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.failure-item:hover {
    background: var(--color-bg-elevated);
}

.failure-icon {
    color: var(--color-danger);
    margin-right: var(--space-2);
}

.failure-info {
    flex: 1;
    min-width: 0;
}

.failure-name {
    font-weight: 500;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.failure-detail {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   Page-Specific: Admin Tab - Source Cards
   ============================================================ */
.source-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-2);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.source-card:hover {
    background: var(--color-bg-elevated);
}

.source-info {
    flex: 1;
    min-width: 0;
}

.source-name {
    font-weight: 500;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.source-meta {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.source-status {
    font-size: var(--text-sm);
    margin-left: var(--space-2);
}

.source-status.sleeping {
    color: var(--color-text-muted);
}

.source-status.failing {
    color: var(--color-danger);
}

.source-status.ok {
    color: var(--color-success);
}

.section-header.sleeping {
    color: var(--color-text-muted);
}

.section-header.warning {
    color: var(--color-warning);
}
