*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --text: #1f2430;
    --text-secondary: #7b8499;
    --border: #e4e8f0;
    --accent: #5b6cff;
    --accent-hover: #4a59eb;
    --accent-soft: rgba(91, 108, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow: 0 4px 16px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.08);
    --radius: 16px;
    --radius-sm: 12px;
    --transition: 180ms ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.sidebar {
    padding: 20px;
    height: fit-content;
    position: sticky;
    top: 20px;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 28px;
}

.brand__logo {
    display: block;
    width: 100%;
    max-width: 200px;
    height: auto;
}

.brand__tag {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}

.nav-item__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c5cad6;
    flex-shrink: 0;
}

.nav-item--active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}

.nav-item--active .nav-item__dot {
    background: var(--accent);
}

.content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.page-header {
    padding: 22px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-header__title {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-header__logo {
    display: block;
    max-width: 180px;
    height: auto;
}

.page-header__subtitle {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.page-header__user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.page-header__user-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace {
    width: 100%;
}

.upload-phase,
.preview-phase {
    width: 100%;
}

.box--upload {
    padding: 24px;
}

.box__header {
    margin-bottom: 18px;
}

.box__title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.box__desc {
    margin-top: 4px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.drop-zone:hover,
.drop-zone--active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px rgba(91, 108, 255, 0.15);
}

.drop-zone__icon-wrap {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.drop-zone__icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.drop-zone__text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), opacity var(--transition), box-shadow var(--transition);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn--block {
    width: 100%;
}

.btn--sm {
    padding: 8px 14px;
    font-size: 0.82rem;
}

.btn--primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(91, 108, 255, 0.28);
}

.btn--primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn--secondary {
    background: var(--surface);
    color: var(--accent);
    border: 1px solid rgba(91, 108, 255, 0.35);
}

.btn--secondary:hover:not(:disabled) {
    background: var(--accent-soft);
}

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.btn--ghost:hover:not(:disabled) {
    color: var(--text);
    background: #f4f6fa;
    border-color: var(--border);
}

.btn--back {
    padding-left: 10px;
}

.btn__icon {
    width: 18px;
    height: 18px;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.preview-layout {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(300px, 380px);
    gap: 16px;
    align-items: start;
}

.preview-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.box--grid,
.box--action,
.box--steps,
.box--ai {
    padding: 20px;
}

.box__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.box__badge {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 4px 10px;
    border-radius: 999px;
}

.grid-hint {
    margin-bottom: 16px;
    padding: 14px 16px;
    background: #f8f9fc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.grid-hint__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.grid-hint__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.grid-hint__list li {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding-left: 14px;
    position: relative;
}

.grid-hint__list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
}

.grid-hint__list strong {
    color: var(--text);
    font-weight: 600;
}

.phone {
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
    background: #1d1d1f;
    border-radius: 36px;
    padding: 10px;
    box-shadow: var(--shadow-lg);
}

.phone__notch {
    width: 110px;
    height: 24px;
    background: #1d1d1f;
    border-radius: 0 0 14px 14px;
    margin: 0 auto -12px;
    position: relative;
    z-index: 1;
}

.phone__screen {
    background: var(--surface);
    border-radius: 26px;
    overflow: hidden;
}

.phone__header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #efefef;
}

.phone__username {
    font-size: 0.85rem;
    font-weight: 600;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    position: relative;
}

.grid-item {
    aspect-ratio: 1 / 1;
    overflow: hidden;
    cursor: grab;
    position: relative;
    background: #efefef;
    touch-action: none;
}

.grid-item:active {
    cursor: grabbing;
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.grid-item--ghost {
    opacity: 0.4;
}

.grid-item--dragging {
    opacity: 0.85;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.steps {
    margin-top: 14px;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    counter-reset: step;
}

.steps li {
    display: flex;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    counter-increment: step;
}

.steps li::before {
    content: counter(step);
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 7px;
    background: #f4f6fa;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.steps a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.steps a:hover {
    text-decoration: underline;
}

.steps strong {
    color: var(--text);
    font-weight: 600;
}

.ai-panel__textarea {
    width: 100%;
    margin-top: 12px;
    margin-bottom: 12px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    font: inherit;
    color: var(--text);
    background: #fafbfc;
    min-height: 120px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.ai-panel__textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--surface);
}

.toast {
    margin-top: 16px;
    padding: 12px 16px;
    font-size: 0.875rem;
    color: #b42318;
    background: #fef3f2;
    border: 1px solid #fecdca;
    border-radius: var(--radius-sm);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.toast--success {
    color: #027a48;
    background: #ecfdf3;
    border-color: #abefc6;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 32px 28px;
}

.login-card__brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 28px;
}

.login-card__logo {
    display: block;
    width: 100%;
    max-width: 220px;
    height: auto;
}

.login-card__title {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.login-card__subtitle {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.login-card__error {
    margin-bottom: 16px;
    padding: 12px 14px;
    font-size: 0.875rem;
    color: #b42318;
    background: #fef3f2;
    border: 1px solid #fecdca;
    border-radius: var(--radius-sm);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-form__label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    margin-top: 8px;
}

.login-form__input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    color: var(--text);
    background: #fafbfc;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.login-form__input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--surface);
}

.login-form .btn {
    margin-top: 16px;
}

.login-card__hint {
    margin-bottom: 16px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .sidebar {
        position: static;
    }

    .sidebar__nav {
        flex-direction: row;
    }

    .preview-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header__logo {
        max-width: 150px;
    }

    .phone {
        border-radius: 28px;
        padding: 8px;
    }

    .phone__screen {
        border-radius: 22px;
    }

    .sidebar__nav {
        flex-direction: column;
    }
}
