:root {
    --bg: #0b0f17;
    --bg-elevated: #121826;
    --bg-card: #161f30;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f4f7fb;
    --text-muted: #94a3b8;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.15);
    --pending: #fbbf24;
    --processing: #38bdf8;
    --completed: #34d399;
    --error: #f87171;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --radius: 18px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top, rgba(91, 140, 255, 0.18), transparent 32%),
        var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100dvh;
    padding:
        calc(16px + var(--safe-top))
        16px
        calc(24px + var(--safe-bottom));
}

.screen {
    max-width: 560px;
    margin: 0 auto;
}

.login-card,
.panel {
    background: rgba(18, 24, 38, 0.92);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.login-card {
    margin-top: 12vh;
    padding: 28px 22px;
    text-align: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: #c7d7ff;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login-card h1 {
    margin: 18px 0 10px;
    font-size: 1.75rem;
    line-height: 1.15;
}

.login-card p {
    margin: 0 0 24px;
    color: var(--text-muted);
    line-height: 1.5;
}

.google-wrap {
    display: flex;
    justify-content: center;
    min-height: 44px;
}

.alert {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.25);
    color: #fecaca;
    font-size: 0.92rem;
    line-height: 1.45;
}

.alert.success {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.25);
    color: #a7f3d0;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 0 18px;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.login-divider::before,
.login-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.email-form {
    display: grid;
    gap: 12px;
    text-align: left;
}

.email-form label {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.email-input,
.primary-button {
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
}

.email-input {
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.email-input:focus {
    outline: 2px solid rgba(91, 140, 255, 0.35);
    border-color: rgba(91, 140, 255, 0.45);
}

.primary-button {
    appearance: none;
    border: 0;
    background: linear-gradient(135deg, #5b8cff, #4f7dff);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.primary-button:active:not(:disabled) {
    transform: scale(0.98);
}

.email-hint {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.add-task-panel {
    margin-bottom: 18px;
}

.add-task-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.add-task-toggle-label {
    font-size: 1rem;
    font-weight: 600;
}

.add-task-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: #c7d7ff;
    font-size: 1.4rem;
    line-height: 1;
    transition: transform 0.2s ease;
}

.add-task-toggle[aria-expanded="true"] .add-task-toggle-icon {
    transform: rotate(45deg);
}

.add-task-form {
    display: grid;
    gap: 12px;
    padding: 0 18px 18px;
    border-top: 1px solid var(--border);
}

.add-task-form label {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: var(--text);
    cursor: pointer;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

#add-task-feedback {
    margin-top: 0;
}

.task-textarea {
    min-height: 110px;
    padding: 12px 14px;
    resize: vertical;
}

.field-select {
    appearance: none;
    padding: 0 14px;
    background:
        rgba(255, 255, 255, 0.04)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
        no-repeat right 14px center;
}

.bot-list {
    display: grid;
    gap: 10px;
    margin-top: 8px;
}

.bot-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
}

.bot-item-copy strong {
    display: block;
    margin-bottom: 4px;
}

.bot-item-copy p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}

.bot-delete-button {
    flex-shrink: 0;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(248, 113, 113, 0.25);
    background: rgba(248, 113, 113, 0.12);
    color: #fecaca;
    cursor: pointer;
}

.task-title {
    margin: 0 0 8px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.task-instructions {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.topbar-copy h1 {
    margin: 0;
    font-size: 1.35rem;
}

.topbar-copy p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-button,
.ghost-button {
    appearance: none;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    border-radius: 14px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 14px;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.icon-button:active,
.ghost-button:active {
    transform: scale(0.98);
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.12);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat-card {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}

.stat-card.pending .stat-value { color: var(--pending); }
.stat-card.processing .stat-value { color: var(--processing); }
.stat-card.completed .stat-value { color: var(--completed); }
.stat-card.error .stat-value { color: var(--error); }

.panel {
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    margin: 0;
    font-size: 1rem;
}

.panel-link {
    color: #c7d7ff;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.back-link {
    display: inline-block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-decoration: none;
}

.filters-panel {
    margin-bottom: 18px;
    padding: 16px 18px;
}

.filters-grid {
    display: grid;
    gap: 10px;
}

.filters-grid label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.tasks-detail-list {
    display: grid;
    gap: 14px;
}

.task-detail-card {
    padding: 0;
}

.task-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.task-detail-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.task-delete-button {
    min-height: 36px;
}

.task-detail-header h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
    line-height: 1.35;
    word-break: break-word;
}

.task-detail-id {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    word-break: break-all;
}

.task-detail-fields {
    margin: 0;
    padding: 8px 18px 16px;
}

.detail-field {
    display: grid;
    gap: 4px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.detail-field:last-child {
    border-bottom: 0;
}

.detail-field dt {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.detail-field dd {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.45;
    word-break: break-word;
}

.task-json {
    margin: 0;
    padding: 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--border);
    overflow-x: auto;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.live-dot::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--completed);
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
    70% { box-shadow: 0 0 0 10px rgba(52, 211, 153, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.task-list {
    display: flex;
    flex-direction: column;
}

.task-card {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.task-card:last-child {
    border-bottom: 0;
}

.task-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.task-id {
    font-size: 0.82rem;
    color: var(--text-muted);
    word-break: break-all;
}

.status-pill {
    flex-shrink: 0;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.status-pill.pending {
    background: rgba(251, 191, 36, 0.14);
    color: #fde68a;
}

.status-pill.processing {
    background: rgba(56, 189, 248, 0.14);
    color: #bae6fd;
}

.status-pill.completed {
    background: rgba(52, 211, 153, 0.14);
    color: #a7f3d0;
}

.status-pill.error {
    background: rgba(248, 113, 113, 0.14);
    color: #fecaca;
}

.task-url {
    display: block;
    color: var(--text);
    text-decoration: none;
    font-size: 0.95rem;
    line-height: 1.45;
    word-break: break-word;
}

.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.empty-state,
.loading-state {
    padding: 36px 22px;
    text-align: center;
    color: var(--text-muted);
}

.loading-state {
    display: grid;
    gap: 12px;
}

.skeleton {
    height: 72px;
    border-radius: 16px;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04),
        rgba(255, 255, 255, 0.08),
        rgba(255, 255, 255, 0.04)
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (min-width: 640px) {
    .app-shell {
        padding-left: 24px;
        padding-right: 24px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .live-dot::before,
    .skeleton {
        animation: none;
    }
}
