* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #fafaf9;
    --bg-soft: #f5f5f4;
    --surface: #ffffff;
    --surface-soft: #fafaf9;

    --text: #1c1917;
    --text-soft: #44403c;
    --muted: #78716c;
    --muted-soft: #a8a29e;

    --border: #e7e5e4;
    --border-soft: #f1f0ee;

    --primary: #1c1917;
    --primary-hover: #292524;

    --accent: #6366f1;
    --accent-soft: #eef2ff;
    --accent-hover: #4f46e5;

    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.05), 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow: 0 4px 6px -1px rgba(28, 25, 23, 0.05), 0 2px 4px -2px rgba(28, 25, 23, 0.04);
    --shadow-md: 0 10px 15px -3px rgba(28, 25, 23, 0.06), 0 4px 6px -4px rgba(28, 25, 23, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(28, 25, 23, 0.08), 0 8px 10px -6px rgba(28, 25, 23, 0.05);

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.fade-in { animation: fadeInUp 0.4s ease both; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

/* HEADER */
header {
    background: rgba(250, 250, 249, 0.85);
    border-bottom: 1px solid var(--border-soft);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 18px 0;
}

header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.02em;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity var(--transition);
}

.logo:hover {
    opacity: 0.75;
}

.logo-icon {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 26px;
    height: 26px;
    stroke: var(--text);
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

h2 {
    font-size: 26px;
    margin-bottom: 24px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.025em;
}

h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}


/* BUTTONS */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: all var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.btn-primary {
    background: var(--text);
    color: white;
    box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-soft);
    border-color: var(--muted-soft);
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}

.btn-danger {
    background: var(--surface);
    color: var(--danger);
    border: 1px solid var(--border);
}

.btn-danger:hover {
    background: var(--danger-soft);
    border-color: #fecaca;
}

/* Icon-only button */
.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-icon:hover {
    background: #e7e5e4;
    border-color: #d6d3d1;
}

/* FORMS */
input[type="text"],
input[type="password"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 11px 14px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    color: var(--text);
    letter-spacing: -0.01em;
}

input::placeholder, textarea::placeholder {
    color: var(--muted-soft);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(28, 25, 23, 0.06);
}

textarea {
    min-height: 100px;
    resize: vertical;
}

label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-soft);
    margin-bottom: 6px;
    display: block;
}

/* Input with icon */
.input-icon {
    position: relative;
    margin-bottom: 14px;
}

.input-icon svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--muted);
    pointer-events: none;
    transition: color var(--transition);
}

.input-icon input {
    padding-left: 40px !important;
    margin-bottom: 0 !important;
}

.input-icon input:focus + svg,
.input-icon:focus-within svg {
    color: var(--text);
}

/* CARDS */
.test-card, .form-card {
    background: var(--surface);
    padding: 22px;
    border-radius: var(--radius);
    margin-bottom: 0;
    border: 1px solid var(--border-soft);
    transition: all var(--transition);
    animation: fadeInUp 0.4s ease both;
    display: flex;
    flex-direction: column;
}

.test-card {
    cursor: default;
    min-height: 220px;
    position: relative;
    overflow: hidden;
}

.test-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--text), var(--text-soft));
    opacity: 0;
    transition: opacity var(--transition);
}

.test-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--border);
}

.test-card:hover::before {
    opacity: 1;
}

.test-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text);
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.015em;
}

.test-card p {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 14px;
    flex: 1;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.meta-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.meta-item svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    flex-shrink: 0;
}

.meta-item.success {
    color: var(--success);
}

.meta-item.danger {
    color: var(--danger);
}

/* Tests grid */
#testsContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

@media (min-width: 1100px) {
    #testsContainer {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    #testsContainer {
        grid-template-columns: 1fr;
    }
}

.form-card {
    max-width: 440px;
    margin: 60px auto;
    padding: 36px;
    box-shadow: var(--shadow-md);
    animation: scaleIn 0.3s ease;
}

.form-card h2 {
    font-size: 22px;
    margin-bottom: 8px;
    text-align: center;
}


/* TABS */
.tabs {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 28px;
    background: var(--bg-soft);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
}

.tab {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--muted);
    transition: all var(--transition);
    letter-spacing: -0.01em;
}

.tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

.tab:hover:not(.active) {
    color: var(--text);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

/* QUESTION BLOCKS */
.question-block {
    background: var(--surface);
    padding: 22px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid var(--border-soft);
    animation: fadeInUp 0.3s ease both;
    transition: border-color var(--transition);
}

.question-block:hover {
    border-color: var(--border);
}

.question-block h4 {
    margin-bottom: 14px;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.question-block .q-title {
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text);
    font-size: 16px;
    letter-spacing: -0.015em;
    line-height: 1.4;
}

/* User test - options */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

@media (min-width: 769px) {
    .options-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .options-grid {
        grid-template-columns: 1fr;
    }
}

.option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all var(--transition);
    font-size: 14px;
}

.option-row:hover {
    border-color: var(--text);
    background: var(--bg-soft);
}

.option-row:has(input:checked) {
    border-color: var(--text);
    background: var(--text);
    color: white;
}

.option-row input[type="radio"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--text);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.option-row span {
    flex: 1;
    line-height: 1.4;
}

.option-row label {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    cursor: pointer;
    margin: 0;
    font-size: 14px;
    color: inherit;
}

/* Admin: answer options when creating test */
.answers-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

@media (max-width: 768px) {
    .answers-container {
        grid-template-columns: 1fr;
    }
}

.answer-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    transition: all var(--transition);
}

.answer-option:focus-within {
    border-color: var(--text);
    background: var(--surface);
}

.answer-option input[type="text"] {
    flex: 1;
    margin-bottom: 0;
    padding: 6px 8px;
    font-size: 13px;
    background: transparent;
    border: none;
}

.answer-option input[type="text"]:focus {
    box-shadow: none;
    outline: none;
}

.answer-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--success);
    flex-shrink: 0;
}

/* Buttons in question block */
.question-block .btn-secondary,
.question-block .btn-primary,
.question-block .remove-btn {
    margin-top: 8px;
    margin-right: 6px;
    font-size: 13px;
    padding: 7px 14px;
}

.remove-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all var(--transition);
}

.remove-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #fecaca;
}

.remove-answer-btn {
    background: transparent;
    color: var(--muted-soft);
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.remove-answer-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}


/* ADMIN GRID */
#adminTestsList,
#inactiveTestsList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

@media (min-width: 1100px) {
    #adminTestsList,
    #inactiveTestsList {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    #adminTestsList,
    #inactiveTestsList {
        grid-template-columns: 1fr;
    }
}

.admin-test-item {
    background: var(--surface);
    padding: 22px;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px solid var(--border-soft);
    transition: all var(--transition);
    animation: fadeInUp 0.3s ease both;
    position: relative;
    overflow: hidden;
}

.admin-test-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--text);
    opacity: 0;
    transition: opacity var(--transition);
}

.admin-test-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--border);
}

.admin-test-item:hover::before {
    opacity: 1;
}

.admin-test-item h3 {
    font-size: 17px;
    margin-bottom: 4px;
    color: var(--text);
    font-weight: 600;
}

.admin-test-item p {
    font-size: 13px;
    color: var(--muted);
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.admin-test-item .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.admin-test-item .actions button {
    padding: 8px 12px !important;
    font-size: 12px !important;
    min-width: 0;
    width: 100%;
    border-radius: 6px !important;
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}

.admin-test-item .actions button:hover {
    background: #e7e5e4 !important;
    border-color: #d6d3d1 !important;
}

.admin-test-item .actions button.btn-danger {
    color: var(--danger) !important;
}

.admin-test-item .actions button.btn-danger:hover {
    background: #fee2e2 !important;
    border-color: #fecaca !important;
}

/* Если кнопок 3 — последняя растягивается на 2 колонки */
.admin-test-item .actions button:nth-child(3):last-child {
    grid-column: 1 / -1;
}

/* TABLES */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-top: 20px;
}

.data-table th, .data-table td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
    font-size: 14px;
}

.data-table th {
    background: var(--bg-soft);
    color: var(--text);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-soft);
}

/* RESULT */
.result-card {
    background: var(--surface);
    padding: 56px 40px;
    border-radius: var(--radius-lg);
    text-align: center;
    margin-top: 30px;
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow);
    animation: scaleIn 0.4s ease both;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.result-card h3 {
    font-size: 20px;
    margin-bottom: 12px;
    color: var(--muted);
    font-weight: 500;
    letter-spacing: -0.01em;
}

.result-card .score {
    font-size: 72px;
    font-weight: 700;
    color: var(--text);
    margin: 16px 0;
    letter-spacing: -0.04em;
    line-height: 1;
}

.result-card p {
    font-size: 15px;
    color: var(--muted);
    margin-bottom: 24px;
}

.result-card .btn-primary {
    padding: 12px 28px;
    font-size: 14px;
}

/* BADGES */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-soft);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge-info {
    background: var(--bg-soft);
    color: var(--muted);
    border: 1px solid var(--border);
}

/* HINTS */
.hint {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
}

/* ALERTS */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    animation: fadeIn 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-success {
    background: var(--success-soft);
    color: var(--success);
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
}

/* PAGE HEADER (h2 with search) */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header h2 {
    margin: 0;
}

.search-input {
    max-width: 280px;
    margin: 0 !important;
    padding-left: 38px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.search-wrap {
    max-width: 280px;
    width: 100%;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .search-wrap {
        max-width: 100%;
    }
}

/* DATETIME picker box */
.datetime-box {
    background: var(--bg-soft);
    padding: 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--border-soft);
}

.datetime-box label {
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}

.datetime-box .hint-text {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

/* SWITCH */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    position: relative;
    margin-bottom: 0 !important;
}

.switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    background: var(--border);
    border-radius: 999px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.switch .slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.switch input:checked + .slider {
    background: var(--text);
}

.switch input:checked + .slider::before {
    transform: translateX(16px);
}

.switch .switch-label {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
    grid-column: 1 / -1;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 14px;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }
    
    header .container {
        flex-direction: row;
        align-items: center;
    }
    
    h1 {
        font-size: 18px;
    }
    
    h2 {
        font-size: 22px;
    }
    
    .tabs {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .form-card {
        padding: 28px 22px;
        margin: 30px auto;
    }
    
    .search-input {
        max-width: 100%;
        width: 100%;
    }
    
    .result-card {
        padding: 40px 24px;
    }
    
    .result-card .score {
        font-size: 56px;
    }
}
