/* ==================== YM Clicker Mini App ==================== */

:root {
    --bg: #0f1117;
    --bg2: #181a22;
    --bg3: #1e2130;
    --card: #1a1d28;
    --border: #2a2d3a;
    --text: #e4e6ed;
    --text2: #8b8fa3;
    --text3: #5c5f72;
    --accent: #fc0;
    --accent2: #e6b800;
    --accent-bg: rgba(255, 204, 0, 0.08);
    --green: #34d058;
    --green-bg: rgba(52, 208, 88, 0.1);
    --red: #f85149;
    --red-bg: rgba(248, 81, 73, 0.1);
    --blue: #58a6ff;
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px 24px;
}

/* ==================== Header ==================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 4px 10px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

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

.logo { font-size: 22px; }

.title {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #ff9500);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.user-badge {
    font-size: 12px;
    color: var(--text2);
    background: var(--bg3);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.workers-badge {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
}

/* ==================== Tabs ==================== */

.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg2);
    border-radius: var(--radius);
    margin-bottom: 14px;
    position: sticky;
    top: 52px;
    z-index: 99;
}

.tab {
    flex: 1;
    padding: 9px 0;
    border: none;
    background: transparent;
    color: var(--text3);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab.active {
    background: var(--bg3);
    color: var(--text);
}

.tab:active { transform: scale(0.97); }

/* ==================== Tab Content ==================== */

.tab-content { display: none; }

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s;
}

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

/* ==================== Form ==================== */

.form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.field { margin-bottom: 12px; }

.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.field input, .field select {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text3); }

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

.field-row { display: flex; gap: 10px; }
.field.half { flex: 1; margin-bottom: 12px; }

/* ==================== Buttons ==================== */

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.btn-primary {
    flex: 1;
    padding: 13px;
    background: linear-gradient(135deg, var(--accent), #e6a800);
    border: none;
    border-radius: var(--radius-sm);
    color: #000;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-primary.btn-sm {
    padding: 10px 18px;
    font-size: 14px;
    flex: unset;
}

.btn-save {
    width: 48px;
    padding: 13px 0;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-save:active { transform: scale(0.95); background: var(--accent-bg); }

.btn-danger {
    flex: 1;
    padding: 11px;
    background: var(--red);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:active { transform: scale(0.97); }

.btn-danger-outline {
    flex: 1;
    padding: 11px;
    background: transparent;
    border: 1px solid var(--red);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger-outline:active { transform: scale(0.97); background: var(--red-bg); }

.btn-danger-outline.full-width { flex: unset; width: 100%; margin-top: 8px; }

/* ==================== Task Cards (parallel) ==================== */

.task-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
}

.task-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.task-id {
    font-size: 11px;
    color: var(--text3);
    background: var(--bg);
    padding: 2px 7px;
    border-radius: 6px;
    font-family: 'SF Mono', monospace;
}

.task-threads {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
}

.task-time {
    font-size: 11px;
    color: var(--text3);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.task-query {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 3px;
    word-break: break-word;
}

.task-meta {
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 12px;
    word-break: break-all;
}

.task-stats {
    display: flex;
    gap: 12px;
    font-size: 12px;
    margin-bottom: 10px;
}

.ts-done { color: var(--text2); }
.ts-ok { color: var(--green); font-weight: 600; }
.ts-fail { color: var(--red); }

.btn-stop-task {
    width: 100%;
    padding: 9px;
    background: transparent;
    border: 1px solid var(--red);
    border-radius: 6px;
    color: var(--red);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-stop-task:active { background: var(--red-bg); transform: scale(0.97); }

.btn-secondary {
    width: 100%;
    padding: 11px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:active { transform: scale(0.97); }

.btn-ghost {
    background: none;
    border: none;
    color: var(--text3);
    font-size: 13px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-family: inherit;
}

.btn-ghost:active { background: var(--bg3); color: var(--text2); }

/* ==================== Status ==================== */

.status-empty {
    text-align: center;
    color: var(--text3);
    padding: 24px 0;
    font-size: 14px;
}

/* ==================== Progress ==================== */

.progress-wrap { margin-bottom: 14px; }

.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--green));
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 12px;
    color: var(--text2);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

/* ==================== Patterns ==================== */

.patterns-list { display: flex; flex-direction: column; gap: 8px; }

.pattern-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    transition: border-color 0.15s;
}

.pattern-card:active { border-color: var(--accent); }

.pattern-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.pattern-name {
    font-size: 15px;
    font-weight: 700;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pattern-clicks {
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
    margin-left: 8px;
}

.pattern-meta {
    font-size: 12px;
    color: var(--text3);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pattern-query {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 10px;
}

.pattern-actions {
    display: flex;
    gap: 6px;
}

.pattern-actions .btn-go {
    flex: 1;
    padding: 8px;
    background: linear-gradient(135deg, var(--accent), #e6a800);
    border: none;
    border-radius: 6px;
    color: #000;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.pattern-actions .btn-go:active { transform: scale(0.97); }

.pattern-actions .btn-fill {
    padding: 8px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.pattern-actions .btn-fill:active { background: var(--bg); }

.pattern-actions .btn-del {
    padding: 8px 10px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--red);
    font-size: 13px;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.15s;
}

.pattern-actions .btn-del:active { opacity: 1; background: var(--red-bg); }

/* ==================== History ==================== */

.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.history-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.history-query {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    margin-left: 8px;
}

.history-status.done { color: var(--green); background: var(--green-bg); }
.history-status.stopped { color: var(--red); background: var(--red-bg); }

.history-meta { font-size: 12px; color: var(--text3); }

.history-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text2);
}

.history-clicks { font-variant-numeric: tabular-nums; }
.history-clicks .ok { color: var(--green); font-weight: 600; }
.history-clicks .fail { color: var(--red); }

.history-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

/* ==================== Users ==================== */

.users-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.user-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-item-left { flex: 1; }
.user-item-name { font-size: 14px; font-weight: 600; }
.user-item-id { font-size: 11px; color: var(--text3); font-family: 'SF Mono', monospace; }

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

.user-threads {
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.user-role { font-size: 11px; color: var(--blue); font-weight: 600; }

.btn-remove {
    background: none;
    border: none;
    color: var(--red);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-remove:active { opacity: 1; }

/* ==================== Modal ==================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 380px;
    animation: modalIn 0.2s;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 14px;
}

.modal-preview {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 16px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.modal-actions .btn-secondary { flex: 1; }
.modal-actions .btn-primary { flex: 1; }

/* ==================== Toast ==================== */

.toast {
    position: fixed;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    transition: bottom 0.3s ease;
    white-space: nowrap;
    max-width: 90%;
    text-align: center;
}

.toast.show { bottom: 30px; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); color: var(--green); }

/* ==================== Scrollbar ==================== */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
