/* ========================================
   Marked OS — Reusable Components
   ======================================== */

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:active::after {
    opacity: 0.15;
}

.btn-primary {
    background: var(--primary-gradient);
    color: var(--text-inverse);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
    background: var(--primary-gradient-hover);
    box-shadow: 0 6px 18px rgba(163, 21, 53, 0.35);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary-200);
}

.btn-outline:hover {
    background: var(--primary-50);
    border-color: var(--primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #B91C1C;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-full {
    width: 100%;
}

.btn-text {
    position: relative;
    z-index: 1;
}

.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    position: relative;
    z-index: 1;
}

.text-btn {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--primary);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.text-btn:hover {
    color: var(--primary-light);
}

/* ---- Icon Buttons ---- */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn:hover {
    background: var(--bg-secondary);
}

.icon-btn-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    color: var(--text-tertiary);
}

.icon-btn-sm svg {
    width: 16px;
    height: 16px;
}

.icon-btn-sm:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ---- Avatar ---- */
.avatar-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    color: white;
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.avatar-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 0 0 3px var(--primary-100);
}

/* ---- Form Groups ---- */
.form-group {
    margin-bottom: var(--space-4);
}

.form-row {
    display: flex;
    gap: var(--space-3);
}

.form-row .form-group {
    margin-bottom: var(--space-4);
}

.flex-1 {
    flex: 1;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper input {
    padding-left: 40px;
}

.input-icon {
    position: absolute;
    left: 12px;
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    pointer-events: none;
    z-index: 1;
}

.password-toggle {
    position: absolute;
    right: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    z-index: 1;
}

.password-toggle svg {
    width: 18px;
    height: 18px;
}

.password-toggle:hover {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.form-error {
    display: block;
    font-size: var(--text-xs);
    color: var(--danger);
    margin-top: var(--space-1);
    min-height: 16px;
}

.select-wrapper {
    position: relative;
}

/* ---- Password Strength ---- */
.password-strength {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.strength-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0%;
    border-radius: var(--radius-full);
    transition: width var(--transition-base), background var(--transition-base);
    background: var(--danger);
}

.strength-text {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ---- Tags Input ---- */
.tags-input {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    padding: var(--space-2);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-md);
    min-height: 42px;
    cursor: text;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.tags-input:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.tags-input input {
    border: none;
    padding: var(--space-1);
    min-width: 80px;
    flex: 1;
    font-size: var(--text-sm);
    background: transparent;
}

.tags-input input:focus {
    box-shadow: none;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--primary-100);
    color: var(--primary);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.tag-remove {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.tag-remove:hover {
    background: var(--primary-200);
}

.tag-remove svg {
    width: 10px;
    height: 10px;
}

/* ---- Chips ---- */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.chip {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border-default);
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ---- Badge ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary);
}

/* ---- Toggle Switch ---- */
.toggle {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle input {
    display: none;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-base);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-spring);
}

.toggle input:checked+.toggle-slider {
    background: var(--primary);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

/* ---- Color Picker ---- */
.color-picker {
    display: flex;
    gap: var(--space-2);
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.color-swatch span {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.color-swatch.active {
    border-color: var(--text-primary);
    transform: scale(1.15);
}

.color-swatch:hover {
    transform: scale(1.1);
}

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-card);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
    border-color: var(--border-default);
}

/* ---- Empty State ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-10) var(--space-6);
    text-align: center;
    color: var(--text-tertiary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-4);
}

.empty-state p {
    font-size: var(--text-sm);
}

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    top: calc(var(--top-bar-height) + var(--space-4));
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 3px solid var(--primary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    pointer-events: auto;
    animation: slideInRight 0.3s ease, fadeOut 0.3s ease 3.5s forwards;
    max-width: 360px;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast.info {
    border-left-color: var(--info);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: var(--success);
}

.toast.error .toast-icon {
    color: var(--danger);
}

.toast.warning .toast-icon {
    color: var(--warning);
}

.toast.info .toast-icon {
    color: var(--info);
}

/* ---- Modals ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-sm {
    max-width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-5) var(--space-3);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-header h3 {
    font-size: var(--text-lg);
}

.modal-body {
    padding: 0 var(--space-5) var(--space-5);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-2);
}

.modal-footer-right {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
}

/* ---- Priority Badge ---- */
.priority-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    text-transform: capitalize;
}

.priority-badge[data-priority="low"] {
    background: rgba(107, 114, 128, 0.1);
    color: var(--priority-low);
}

.priority-badge[data-priority="medium"] {
    background: rgba(37, 99, 235, 0.1);
    color: var(--priority-medium);
}

.priority-badge[data-priority="high"] {
    background: rgba(217, 119, 6, 0.1);
    color: var(--priority-high);
}

.priority-badge[data-priority="urgent"] {
    background: rgba(220, 38, 38, 0.1);
    color: var(--priority-urgent);
}

/* ---- Status Badge ---- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge[data-status="todo"] {
    background: rgba(107, 114, 128, 0.1);
    color: var(--color-todo);
}

.status-badge[data-status="todo"]::before {
    background: var(--color-todo);
}

.status-badge[data-status="in_progress"] {
    background: rgba(37, 99, 235, 0.1);
    color: var(--color-progress);
}

.status-badge[data-status="in_progress"]::before {
    background: var(--color-progress);
}

.status-badge[data-status="review"] {
    background: rgba(124, 58, 237, 0.1);
    color: var(--color-review);
}

.status-badge[data-status="review"]::before {
    background: var(--color-review);
}

.status-badge[data-status="done"] {
    background: rgba(5, 150, 105, 0.1);
    color: var(--color-done);
}

.status-badge[data-status="done"]::before {
    background: var(--color-done);
}

/* Desktop Responsive for Modal */
@media (min-width: 640px) {
    .modal-overlay {
        align-items: center;
        padding: var(--space-6);
    }

    .modal {
        border-radius: var(--radius-xl);
        max-width: 560px;
    }

    .modal-sm {
        max-width: 400px;
    }
}