/* ========================================
   Design Tokens - Embedded Dev Platform
   ======================================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-elevated: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.5);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;

    --border-default: #e2e8f0;
    --border-strong: #cbd5e1;
    --border-focus: #3b82f6;

    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-blue-light: #eff6ff;
    --accent-green: #10b981;
    --accent-green-light: #ecfdf5;
    --accent-orange: #f59e0b;
    --accent-orange-light: #fffbeb;
    --accent-red: #ef4444;
    --accent-red-light: #fef2f2;
    --accent-purple: #8b5cf6;
    --accent-purple-light: #f5f3ff;
    --accent-cyan: #06b6d4;
    --accent-cyan-light: #ecfeff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;

    --sidebar-width: 240px;
    --header-height: 56px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-elevated: #1e293b;
    --bg-overlay: rgba(0, 0, 0, 0.7);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-inverse: #0f172a;

    --border-default: #334155;
    --border-strong: #475569;
    --border-focus: #60a5fa;

    --accent-blue-light: #1e3a5f;
    --accent-green-light: #064e3b;
    --accent-orange-light: #78350f;
    --accent-red-light: #7f1d1d;
    --accent-purple-light: #4c1d95;
    --accent-cyan-light: #164e63;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
}
.btn:focus { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn-primary { background: var(--accent-purple); color: var(--text-inverse); }
.btn-primary:hover { background: var(--accent-purple); filter: brightness(0.9); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-default); }
.btn-secondary:hover { background: var(--border-default); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-danger { background: var(--accent-red); color: white; }
.btn-success { background: var(--accent-green); color: white; }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: 13px; border-radius: 16px; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: 16px; border-radius: 24px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Inputs */
.input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}
.input:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-blue-light); }
.input::placeholder { color: var(--text-tertiary); }

.select {
    appearance: none;
    width: 100%;
    padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
    font-size: 14px;
    background: var(--bg-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E") no-repeat right 12px center;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
}
.select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-blue-light); }

/* Cards */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-normal);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-default); }
.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-default); background: var(--bg-secondary); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* Tags */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
}
.tag-blue { background: var(--accent-blue-light); color: var(--accent-blue); }
.tag-green { background: var(--accent-green-light); color: var(--accent-green); }
.tag-orange { background: var(--accent-orange-light); color: var(--accent-orange); }
.tag-red { background: var(--accent-red-light); color: var(--accent-red); }
.tag-purple { background: var(--accent-purple-light); color: var(--accent-purple); }

/* Status */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-success { background: var(--accent-green); }
.status-warning { background: var(--accent-orange); }
.status-error { background: var(--accent-red); }
.status-info { background: var(--accent-blue); }

/* Progress */
.progress-bar { width: 100%; height: 6px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent-blue); border-radius: 3px; }

/* Icon button */
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all var(--transition-fast);
}
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Theme toggle */
.theme-toggle {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: transform var(--transition-fast);
    z-index: 1000;
}
.theme-toggle:hover { transform: scale(1.1); }

/* === Premium Button System === */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    letter-spacing: 0.3px;
    border: none;
    cursor: pointer;
    outline: none;
    border-radius: 20px;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
    opacity: 0;
}
.btn:active::after {
    width: 300px;
    height: 300px;
    opacity: 0;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    box-shadow: 0 4px 16px rgba(99,102,241,0.4);
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0) scale(0.98);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 2px 8px rgba(16,185,129,0.3);
}
.btn-success:hover {
    box-shadow: 0 4px 16px rgba(16,185,129,0.4);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}
.btn-danger:hover {
    box-shadow: 0 4px 16px rgba(239,68,68,0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: 20px;
}
.btn-ghost:hover {
    background: var(--bg-secondary);
    border-color: var(--border-strong);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
}
.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: scale(1.05);
}
.icon-btn:active {
    transform: scale(0.95);
}

.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 16px; }
.btn-md { padding: 8px 20px; font-size: 14px; border-radius: 20px; }
.btn-lg { padding: 12px 28px; font-size: 16px; border-radius: 24px; }
.btn-xl { padding: 14px 36px; font-size: 18px; border-radius: 28px; }

.btn.loading {
    pointer-events: none;
    opacity: 0.8;
}
.btn.loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
    margin-right: 8px;
}
@keyframes btnSpin {
    to { transform: rotate(360deg); }
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Button group */
.btn-group {
    display: inline-flex;
    gap: 0;
}
.btn-group .btn {
    border-radius: 0;
}
.btn-group .btn:first-child {
    border-radius: 10px 0 0 10px;
}
.btn-group .btn:last-child {
    border-radius: 0 10px 10px 0;
}
.btn-group .btn + .btn {
    margin-left: -1px;
}

/* === Modal/Dialog System === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}

.modal {
    background: var(--bg-elevated);
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow: hidden;
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--border-default);
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 24px 28px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: all 0.2s;
}
.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-body {
    padding: 8px 28px 24px;
    overflow-y: auto;
    max-height: calc(85vh - 140px);
    color: var(--text-secondary);
}

.modal-footer {
    padding: 16px 28px 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.modal-lg { max-width: 640px; }
.modal-sm { max-width: 380px; }

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: 16px;
    background: var(--bg-elevated);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    animation: toastSlideIn 0.3s ease;
    min-width: 280px;
    border: 1px solid var(--border-default);
}

.toast-success { border-left: 4px solid #10b981; }
.toast-error { border-left: 4px solid #ef4444; }
.toast-warning { border-left: 4px solid #f59e0b; }
.toast-info { border-left: 4px solid #8b5cf6; }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* === Tooltip === */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    background: #1e293b;
    color: white;
    font-size: 12px;
    border-radius: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
}
[data-tooltip]:hover::before {
    opacity: 1;
}

/* ========================================
   Responsive Breakpoints
   ======================================== */

/* Tablet: collapse three-panel to two-panel or stacked */
@media (max-width: 1024px) {
    .workspace {
        grid-template-columns: 1fr 1fr;
    }

    .workspace .panel-third {
        grid-column: span 2;
    }

    .sidebar {
        width: 200px;
    }
}

/* Mobile: full stack layout */
@media (max-width: 768px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .workspace .panel-third,
    .workspace .panel-half {
        grid-column: span 1;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        height: 60px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        z-index: 900;
        border-top: 1px solid var(--border-default);
        background: var(--bg-elevated);
        transform: none;
    }

    .sidebar.collapsed {
        transform: translateY(100%);
    }

    .topbar {
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
    }

    .topbar-title {
        font-size: 14px;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .step-indicator {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        white-space: nowrap;
        padding-bottom: var(--space-2);
    }

    .step-indicator::-webkit-scrollbar {
        display: none;
    }

    .step-indicator .step-item {
        display: inline-block;
        flex-shrink: 0;
    }

    .tag-group {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        scrollbar-width: none;
    }

    .tag-group::-webkit-scrollbar {
        display: none;
    }

    .tag {
        flex-shrink: 0;
    }

    /* Tables to card view */
    .table-responsive {
        border: none;
    }

    .table-responsive table,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive th,
    .table-responsive td,
    .table-responsive tr {
        display: block;
    }

    .table-responsive thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .table-responsive tr {
        background: var(--bg-elevated);
        border: 1px solid var(--border-default);
        border-radius: var(--radius-md);
        margin-bottom: var(--space-3);
        padding: var(--space-3);
        box-shadow: var(--shadow-sm);
    }

    .table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-2) 0;
        border-bottom: 1px solid var(--border-default);
        text-align: right;
    }

    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
        flex: 1;
        padding-right: var(--space-3);
    }

    .table-responsive td:last-child {
        border-bottom: none;
    }

    /* Font and spacing reductions */
    body {
        font-size: 14px;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    h4 { font-size: 1rem; }

    .card-body {
        padding: var(--space-4);
    }

    .card-header {
        padding: var(--space-3) var(--space-4);
    }

    .card-footer {
        padding: var(--space-3) var(--space-4);
    }

    .content-area {
        padding: var(--space-3);
    }
}

/* Small mobile: tighter spacing, smaller fonts */
@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.1rem; }
    h3 { font-size: 1rem; }
    h4 { font-size: 0.9rem; }

    .btn {
        padding: var(--space-1) var(--space-3);
        font-size: 13px;
    }

    .btn-lg {
        padding: var(--space-2) var(--space-4);
        font-size: 14px;
    }

    .input {
        padding: var(--space-1) var(--space-2);
        font-size: 13px;
    }

    .card-body {
        padding: var(--space-3);
    }

    .card-header {
        padding: var(--space-2) var(--space-3);
    }

    .card-footer {
        padding: var(--space-2) var(--space-3);
    }

    .content-area {
        padding: var(--space-2);
    }

    .topbar {
        padding: var(--space-1) var(--space-2);
        height: 48px;
    }

    .sidebar {
        height: 52px;
    }

    .tag {
        font-size: 11px;
        padding: 1px var(--space-1);
    }

    .theme-toggle {
        width: 40px;
        height: 40px;
        font-size: 16px;
        bottom: 70px;
        right: var(--space-4);
    }
}

/* ========================================
   Interaction Animations
   ======================================== */

/* Keyframes */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes ripple-expand {
    from {
        transform: scale(0);
        opacity: 0.5;
    }
    to {
        transform: scale(4);
        opacity: 0;
    }
}

@keyframes pageIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Animation utility classes */
.animate-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.animate-slide-up {
    animation: slideUp 0.4s ease forwards;
}

.animate-slide-in {
    animation: slideIn 0.3s ease forwards;
}

.animate-pulse {
    animation: pulse 2s infinite;
}

/* Skeleton loading placeholder */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--border-default) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton * {
    visibility: hidden;
}

/* Material-design ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    border-radius: 50%;
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

.ripple:active::after {
    animation: ripple-expand 0.6s ease-out;
}

/* Enhanced card hover */
.card {
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

/* Button active scale */
.btn:active:not(:disabled) {
    transform: scale(0.97);
}

/* Button focus-visible ring */
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-blue-light), 0 0 0 5px var(--accent-blue);
}

/* Page transition */
.page-enter {
    animation: pageIn 0.3s ease-out;
}

/* Smooth theme toggle transitions */
*:not(.no-transition) {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
