:root {
    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;

    --success-bg: #dcfce7;
    --success-text: #166534;
    --failure-bg: #fee2e2;
    --failure-text: #991b1b;
    --progress-bg: #fef3c7;
    --progress-text: #92400e;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

.header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 0;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.header-logo {
    color: var(--text-primary);
}

.header-logo:hover {
    color: var(--text-primary);
    text-decoration: none;
}

.header-nav a,
.header-link {
    color: var(--text-secondary);
    font-size: 14px;
}

.header-nav a:hover,
.header-link:hover {
    color: var(--text-primary);
}

.header-nav a svg {
    display: block;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-muted);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.pip-btn:hover {
    background: var(--bg-primary);
    color: var(--text-secondary);
    text-decoration: none;
}

.pip-btn svg {
    display: block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

main.container {
    padding-top: 32px;
    padding-bottom: 48px;
}

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

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

/* Card styles */
.card {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.github-link {
    font-size: 12px;
    font-weight: 500;
    text-transform: none;
}

/* Deploy button */
.card-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.deploy-form {
    display: inline;
}

.btn-deploy {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.btn-deploy:hover {
    background: var(--accent-hover);
}

.btn-remove {
    background: transparent;
    color: var(--failure-text);
    border: 1px solid var(--failure-bg);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.btn-remove:hover {
    background: var(--failure-bg);
}

/* Flash messages */
.flash {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.flash-error {
    background: var(--failure-bg);
    color: var(--failure-text);
}

/* Table styles */
table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th, td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    overflow: hidden;
    text-overflow: ellipsis;
}

th {
    background: var(--bg-primary);
    font-weight: 500;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr {
    transition: background-color 0.15s ease;
}

tbody tr:hover {
    background: #f8fafc;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Status badges */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.status-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.status-failure {
    background: var(--failure-bg);
    color: var(--failure-text);
}

.status-in_progress {
    background: var(--progress-bg);
    color: var(--progress-text);
}

/* SHA styling */
.digest {
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-secondary);
}

.digest a {
    color: inherit;
}

.digest a:hover {
    color: var(--accent);
}

/* Deploy list (card-based layout) */
.deploy-list {
    display: flex;
    flex-direction: column;
}

.deploy-item {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
    transition: background-color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.deploy-item:last-child {
    border-bottom: none;
}

.deploy-item:hover {
    background: var(--bg-primary);
}

.deploy-item-primary {
    display: flex;
    align-items: center;
    gap: 12px;
}

.deploy-item-secondary {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 16px;
    margin: 0;
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.back-link:hover {
    color: var(--accent);
}

/* Detail page */
.detail-card {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: 24px;
}

.detail-hero {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
}

.detail-hero h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1px;
    background: var(--border-light);
}

.detail-item {
    background: var(--bg-card);
    padding: 16px 24px;
}

.detail-item label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-item .value {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-all;
}

.detail-item .value.mono {
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
}

.error-message {
    padding: 16px 24px;
    background: var(--failure-bg);
    color: var(--failure-text);
    border-top: 1px solid var(--border-color);
}

/* Output section */
.output-card {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.output-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    background: var(--bg-primary);
}

pre {
    margin: 0;
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px 24px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
}

/* Mobile layout */
@media (max-width: 768px) {
    body { padding: 0; }

    .container { padding: 0 16px; }

    main.container {
        padding-top: 20px;
        padding-bottom: 32px;
    }

    .header { padding: 12px 0; }
    .header h1 { font-size: 18px; }

    .card-header { font-size: 13px; padding: 14px 20px; }

    .add-repo-fields {
        flex-direction: column;
        gap: 12px;
    }

    .form-group-submit .form-label { display: none; }

    .form-group-submit {
        width: 100%;
    }

    .form-group-submit .btn-deploy {
        width: 100%;
    }

    .deploy-item { padding: 12px 16px; }
    .deploy-item-secondary { gap: 12px; font-size: 12px; }

    /* Detail page mobile */
    .back-link { margin-bottom: 16px; }

    .detail-hero {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .detail-hero h1 { font-size: 20px; }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .detail-item { padding: 12px 16px; }

    .output-header { padding: 14px 16px; font-size: 13px; }

    pre { padding: 16px; font-size: 12px; }

    .status { padding: 5px 10px; font-size: 10px; }
    .digest { font-size: 12px; padding: 3px 6px; }
}

/* Auth pages (login/logout) */
.auth-page {
    text-align: center;
    margin-top: 4rem;
}

/* Add repo form */
.add-repo-card {
    margin-bottom: 24px;
}

.add-repo-form {
    padding: 20px;
}

.add-repo-fields {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group-repo {
    flex: 3;
    min-width: 0;
}

.form-group-appname {
    flex: 2;
    min-width: 0;
}

.form-group-submit {
    flex-shrink: 0;
}

.form-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-label-optional {
    color: var(--text-muted);
    font-weight: 400;
}

.form-input {
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg-card);
    width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.repo-input-wrapper {
    position: relative;
}

.repo-input-wrapper .form-input {
    padding-right: 32px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    position: absolute;
    right: 10px;
    top: 0;
    bottom: 0;
    margin: auto 0;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--text-muted);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Inline edit form */
.app-dir-edit {
    display: none;
    gap: 4px;
    align-items: center;
}

.app-dir-edit.editing {
    display: flex;
}

.edit-input {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    background: var(--bg-card);
    width: 120px;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-edit {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.btn-edit:hover {
    opacity: 1;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
}

.btn-cancel:hover {
    background: var(--bg-primary);
}

/* Delete form inline */
.delete-form {
    display: inline;
}

/* Tablet tweaks */
@media (min-width: 769px) and (max-width: 1024px) {
    th, td { padding: 12px 16px; font-size: 14px; }
    .container { padding: 0 20px; }
}
