/* =================================================================
   Play Store Tracker — stylesheet
   Token system:
     bg-base      #0b0d12   page background
     bg-surface   #14171f   cards
     bg-raised    #1b1f2a   hover / inputs
     border       #262b38   hairlines
     text-1       #e8eaf0   primary text
     text-2       #8b92a5   muted text
     accent       #6d56f0   violet — primary actions / brand
     accent-2     #3ddc97   green  — "updated" / success state
     danger       #ef5c5c   delete / destructive
   Type:
     Display: 'Space Grotesk' (headings, brand, buttons)
     Body:    system-ui stack
     Data:    ui-monospace stack (versions, package names)
================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
    --bg-base:    #0b0d12;
    --bg-surface: #14171f;
    --bg-raised:  #1b1f2a;
    --border:     #262b38;
    --border-soft:#1d212c;

    --text-1: #e8eaf0;
    --text-2: #8b92a5;
    --text-3: #5a6072;

    --accent:       #6d56f0;
    --accent-dim:   #4d3eb0;
    --accent-soft:  rgba(109, 86, 240, 0.14);
    --accent-2:     #3ddc97;
    --accent-2-soft:rgba(61, 220, 151, 0.14);
    --danger:       #ef5c5c;
    --danger-soft:  rgba(239, 92, 92, 0.12);

    --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Consolas, monospace;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px -12px rgba(0,0,0,0.6);
    --shadow-pop: 0 20px 60px -20px rgba(0,0,0,0.7);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background:
        radial-gradient(1100px 480px at 12% -10%, rgba(109,86,240,0.10), transparent 60%),
        radial-gradient(900px 420px at 100% 0%, rgba(61,220,151,0.06), transparent 55%),
        var(--bg-base);
    color: var(--text-1);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

::selection { background: var(--accent-soft); color: var(--text-1); }

a { color: inherit; }

button {
    font-family: inherit;
    cursor: pointer;
}

input {
    font-family: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

.hidden { display: none !important; }

.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* =================================================================
   Top bar
================================================================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(11, 13, 18, 0.82);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-soft);
}

.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 9px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

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

/* app icon used as the brand logo */
.brand-favicon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
    image-rendering: -webkit-optimize-contrast;
}

.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.01em;
}

.topbar-right { display: flex; align-items: center; gap: 6px; }

/* =================================================================
   Buttons
================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 13.5px;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
    white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #7c66f4; }

.btn-ghost {
    background: var(--bg-surface);
    color: var(--text-1);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); border-color: #313749; }

.btn-ghost.active {
    background: var(--accent-soft);
    border-color: var(--accent-dim);
    color: #b6a9fb;
}

.btn-sm { padding: 7px 11px; font-size: 12px; }

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-2);
}
.btn-icon:hover { background: var(--bg-raised); color: var(--text-1); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: rgba(239,92,92,0.3); }
.btn-icon .icon { width: 16px; height: 16px; }

.btn-icon.spinning .icon { animation: spin 0.9s linear infinite; }

/* =================================================================
   Layout
================================================================= */
.main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

/* =================================================================
   Add app card
================================================================= */
.add-section { margin-bottom: 22px; }

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-card);
}

.card-label {
    display: block;
    font-family: var(--font-display);
    font-size: 12.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-2);
    margin-bottom: 10px;
}

.card-hint {
    font-size: 12.5px;
    color: var(--text-3);
    margin: -4px 0 10px;
}

.add-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.input {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-1);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.input::placeholder { color: var(--text-3); }
.input:hover { border-color: #313749; }
.input:focus { border-color: var(--accent-dim); background: #1d212d; }

.input-url {
    font-family: var(--font-mono);
    font-size: 13.5px;
    resize: vertical;
    min-height: 44px;
    line-height: 1.5;
}

.add-row .btn-primary { flex-shrink: 0; }

.form-msg {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
}
.form-msg.success { background: var(--accent-2-soft); color: var(--accent-2); }
.form-msg.error   { background: var(--danger-soft); color: var(--danger); }

.bulk-results {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.bulk-results li {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12.5px;
    line-height: 1.4;
}
.bulk-results .bl-pkg { color: var(--text-2); font-family: var(--font-mono); flex-shrink: 0; }
.bulk-results .bl-msg { color: var(--text-3); }
.bulk-results li.ok   .bl-status { color: var(--accent-2); }
.bulk-results li.fail .bl-status { color: var(--danger); }
.bulk-results li.skip .bl-status { color: var(--text-3); }
.bulk-results li.skip .bl-pkg    { color: var(--text-3); }
.bulk-results li.skip .bl-msg    { color: var(--text-3); font-style: italic; }
.bulk-results li.pending .bl-status { color: var(--text-3); }
.bulk-summary {
    font-weight: 600;
    margin-bottom: 6px;
}

/* =================================================================
   Toolbar: search + count
================================================================= */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.search-wrap {
    position: relative;
    flex: 1;
    max-width: 420px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-3);
    pointer-events: none;
}

.input-search { padding-left: 36px; }

.app-count {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-3);
    white-space: nowrap;
}

/* =================================================================
   App grid + cards
================================================================= */
.apps-section { position: relative; min-height: 200px; }

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.app-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--shadow-card);
    animation: cardIn 0.35s ease both;
    min-width: 0;
    max-width: 100%;
}

.app-card.just-updated {
    border-color: rgba(61,220,151,0.4);
    box-shadow: 0 0 0 1px rgba(61,220,151,0.18), var(--shadow-card);
}

.app-top {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.app-icon {
    width: 52px;
    height: 52px;
    border-radius: 13px;
    background: var(--bg-raised);
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border-soft);
}

.app-meta { min-width: 0; flex: 1; }

.app-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 15px;
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-dev {
    font-size: 12.5px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.app-pkg {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-version-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 2px;
    min-width: 0;
}

.version-chip {
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-1);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 11px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.version-chip .version-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.version-chip .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-2);
}

.version-chip.diff {
    color: var(--accent-2);
    border-color: rgba(61,220,151,0.35);
    background: var(--accent-2-soft);
}

.last-checked {
    font-size: 11.5px;
    color: var(--text-3);
    flex-shrink: 0;
    white-space: nowrap;
}

.version-updated {
    font-size: 11.5px;
    color: var(--text-3);
    margin-top: -4px;
}

.app-actions {
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
}

.app-actions .btn-icon { flex: 1; width: auto; gap: 6px; font-size: 12px; font-family: var(--font-display); font-weight: 600; }

/* =================================================================
   Empty / loading states
================================================================= */
.state-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 70px 20px;
    color: var(--text-2);
}

.empty-icon { width: 48px; height: 48px; margin-bottom: 14px; opacity: 0.8; }
.empty-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: var(--text-1); margin: 0 0 4px; }
.empty-sub { font-size: 13px; color: var(--text-3); margin: 0; max-width: 280px; }

.spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes cardIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =================================================================
   Modal
================================================================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal[hidden] { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5,6,9,0.7);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.18s ease both;
}

.modal-box {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    max-height: 78vh;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-pop);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.22s cubic-bezier(.2,.8,.3,1) both;
    margin-bottom: 0;
}

@media (min-width: 560px) {
    .modal { align-items: center; }
    .modal-box {
        border-radius: var(--radius-lg);
        border-bottom: 1px solid var(--border);
        margin-bottom: 24px;
    }
}

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

.modal-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: var(--bg-raised);
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover { color: var(--text-1); }

.modal-body {
    padding: 12px 20px 22px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-soft);
}
.history-item:last-child { border-bottom: none; }

.history-version {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 500;
}

.history-date {
    font-size: 12px;
    color: var(--text-3);
}

.history-empty {
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
    padding: 30px 0;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

/* =================================================================
   Toast
================================================================= */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 16px);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-1);
    padding: 12px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-pop);
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 90vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.error { border-color: rgba(239,92,92,0.4); color: #ff9b9b; }
.toast.success { border-color: rgba(61,220,151,0.4); color: var(--accent-2); }

/* =================================================================
   Responsive
================================================================= */
@media (max-width: 640px) {
    .topbar-inner { padding: 8px 12px; gap: 6px; }
    .brand-name { font-size: 15px; }
    .brand-favicon { width: 22px; height: 22px; }
    .topbar-right { gap: 5px; }
    .topbar-right .btn-sm,
    .cron-bar-right .btn-sm { padding: 7px 9px; }
    .topbar-right .btn-sm span,
    .cron-bar-right .btn-sm span { display: none; }
    .main { padding: 18px 14px 72px; }
    .add-row { flex-direction: column; }
    .btn-primary { width: 100%; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-wrap { max-width: none; }
    .app-count { text-align: right; }
    .app-grid { grid-template-columns: 1fr; }

    .cron-bar { gap: 8px; padding: 9px 12px; }
    .cron-bar-left { min-width: 0; flex: 1 1 auto; }
    .cron-bar-left span:last-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .cron-bar-right { flex-shrink: 0; }
}

/* Extra-narrow phones (older/small devices) */
@media (max-width: 380px) {
    .topbar-inner { padding: 7px 10px; }
    .brand-name { font-size: 14px; }
    .brand-favicon { width: 20px; height: 20px; }
    .topbar-right .btn-sm,
    .cron-bar-right .btn-sm { padding: 6px 8px; }
    .topbar-right .icon,
    .cron-bar-right .icon { width: 16px; height: 16px; }
    .cron-bar { padding: 8px 10px; }
}

/* =================================================================
   Cron status bar
================================================================= */
.cron-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 28px;
    padding: 11px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 12.5px;
    color: var(--text-2);
}

.cron-bar-left { display: flex; align-items: center; gap: 8px; }
.cron-bar-right { display: flex; align-items: center; gap: 6px; }

.cron-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    flex-shrink: 0;
    transition: background 0.3s;
}
.cron-dot.ok      { background: var(--accent-2); box-shadow: 0 0 6px rgba(61,220,151,0.5); }
.cron-dot.warn    { background: var(--warning); }
.cron-dot.unknown { background: var(--text-3); }

/* =================================================================
   Cron setup modal (wider than history modal)
================================================================= */
.modal-box--wide { max-width: 560px; }

.cron-intro {
    font-size: 13.5px;
    color: var(--text-2);
    margin: 0 0 20px;
    line-height: 1.6;
}
.cron-intro code { color: var(--accent); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.cron-intro strong { color: var(--text-1); }

.cron-step {
    display: flex;
    gap: 14px;
    margin-bottom: 20px;
    align-items: flex-start;
}
.cron-step-num {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.cron-step-body { flex: 1; }
.cron-step-body strong { display: block; color: var(--text-1); font-size: 13.5px; margin-bottom: 4px; }
.cron-step-body p { margin: 4px 0 0; font-size: 13px; color: var(--text-2); line-height: 1.55; }
.cron-step-body p em { color: var(--text-1); font-style: normal; }
.cron-step-body code { color: var(--accent); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: var(--font-mono); }

.cron-timing-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-top: 10px;
    text-align: center;
}
.cron-timing-grid .cron-field-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.cron-timing-grid code {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-1);
}

.cron-cmd-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-top: 10px;
}
.cron-cmd-box code {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--accent-2);
    word-break: break-all;
    background: none;
    padding: 0;
}
.cron-note { color: var(--warning) !important; font-size: 12px !important; margin-top: 8px !important; }

.cron-log-section { margin-top: 20px; border-top: 1px solid var(--border-soft); padding-top: 14px; }
.cron-log-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.cron-log-header span { font-size: 12.5px; font-weight: 600; color: var(--text-1); }
.cron-log-hint { color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.cron-log-pre {
    background: var(--bg-base);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-2);
    line-height: 1.7;
    max-height: 180px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

/* =================================================================
   Reduced motion
================================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
