* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --background: #ffffff;
    --foreground: #0a0a0a;
    --muted: #fafafa;
    --muted-foreground: #737373;
    --border: #e5e5e5;
    --input: #ffffff;
    --ring: #0a0a0a;
    --radius: 0.5rem;
    --primary: #0a0a0a;
    --primary-foreground: #ffffff;
    --secondary: #fafafa;
    --secondary-foreground: #0a0a0a;
    --danger: #dc2626;
    --danger-foreground: #ffffff;
    --success: #16a34a;
    --error: #dc2626;
    --sidebar-width: 88px;
    --top-nav-height: 64px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: #f5f5f5;
    color: var(--foreground);
    line-height: 1.5;
}

/* Top Navigation Bar */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-nav-height);
    background: var(--background);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    z-index: 1000;
}

.top-nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 20px;
    max-width: 100%;
}

.top-nav-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    display: none; /* Always hidden since sidebar is always collapsed */
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--foreground);
    border-radius: 4px;
    transition: background 0.2s;
}

.sidebar-toggle:hover {
    background: var(--muted);
}

.sidebar-toggle svg {
    display: block;
}

.app-logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--foreground);
    text-decoration: none;
    letter-spacing: -0.025em;
}

.app-logo:hover {
    opacity: 0.8;
}

.top-nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.user-menu-toggle:hover {
    background: var(--muted);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
}

.user-menu-toggle svg {
    transition: transform 0.2s;
}

.user-menu.active .user-menu-toggle svg {
    transform: rotate(180deg);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s;
    z-index: 1001;
}

.user-menu.active .user-menu-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
}

.user-menu-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
}

.user-menu-username {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--foreground);
}

.user-menu-email {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    margin-top: 2px;
}

.user-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--foreground);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.user-menu-item:hover {
    background: var(--muted);
}

.user-menu-item svg {
    flex-shrink: 0;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
    padding-top: var(--top-nav-height);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--top-nav-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--top-nav-height));
    background: var(--muted);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 999;
}

.sidebar-content {
    padding: 12px 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 8px;
}

.sidebar-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 8px;
    color: var(--foreground);
    text-decoration: none;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    width: 72px;
    min-height: 72px;
    margin: 0 auto;
    position: relative;
    text-align: center;
}

.sidebar-nav-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-nav-item.active {
    background: var(--primary);
    color: var(--primary-foreground);
}

.sidebar-nav-item svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.sidebar-nav-item span {
    font-size: 0.625rem;
    line-height: 1.2;
    text-align: center;
    word-break: break-word;
    max-width: 100%;
}

.sidebar-nav-item .message-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    margin: 0;
    font-size: 0.625rem;
    padding: 1px 4px;
    min-width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    max-width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease;
}

.main-content-full {
    margin-left: 0;
    max-width: 100%;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--top-nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 24px;
}

.flash-message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    margin-bottom: 8px;
}

.flash-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.flash-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.flash-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.flash-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0;
    margin-left: 12px;
}

.flash-close:hover {
    opacity: 1;
}

/* Container (for pages without sidebar) */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

/* Legacy header styles (for auth pages) */
header {
    background: var(--foreground);
    color: var(--background);
    padding: 32px;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.875rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.025em;
}

.subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

main {
    padding: 32px;
}

section {
    margin-bottom: 32px;
}

section:last-child {
    margin-bottom: 0;
}

section h2 {
    color: var(--foreground);
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--foreground);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="file"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    background: var(--input);
    color: var(--foreground);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group input[type="password"]:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgba(10, 10, 10, 0.1);
}

.form-group input[type="checkbox"] {
    margin-right: 8px;
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: #1a1a1a;
    border-color: #1a1a1a;
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--muted);
}

.btn-danger {
    background: var(--danger);
    color: var(--danger-foreground);
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-success {
    background: var(--success);
    color: #ffffff;
    border-color: var(--success);
}

.btn-success:hover {
    background: #15803d;
    border-color: #15803d;
}

/* Status Messages */
.status-message {
    margin-top: 12px;
    padding: 12px;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
}

.status-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.success-message {
    background: #dcfce7;
    color: #166534;
    padding: 16px;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid #86efac;
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 16px;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid #fca5a5;
}

.error-message pre {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.875rem;
}

/* Info Section */
.info-section ol {
    margin-left: 24px;
    color: var(--muted-foreground);
}

.info-section li {
    margin-bottom: 8px;
}

.info-section code {
    background: var(--muted);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.links-section {
    margin-top: 32px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
}

.file-info {
    background: var(--muted);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.file-info p {
    margin-bottom: 8px;
}

.file-info code {
    background: var(--background);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.app-url {
    margin-top: 12px;
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

.app-url code {
    background: var(--muted);
    padding: 4px 8px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-uploaded { background: #e3f2fd; color: #1976d2; }
.status-building { background: #fff3e0; color: #f57c00; }
.status-built { background: #e8f5e9; color: #388e3c; }
.status-error { background: #ffebee; color: #d32f2f; }

/* Projects Table */
.projects-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: var(--background);
    border-radius: var(--radius);
    overflow: hidden;
}

.projects-table th,
.projects-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.projects-table th {
    background: var(--muted);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.projects-table tr:hover {
    background: var(--muted);
}

.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--muted-foreground);
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: none; /* Hide toggle since sidebar is always visible as icon bar */
    }

    .main-content {
        padding: 16px;
    }

    .sidebar-overlay {
        display: none;
    }

    .user-name {
        display: none;
    }

    .top-nav-content {
        padding: 0 12px;
    }

    .app-logo {
        font-size: 1.125rem;
    }
}

@media (max-width: 600px) {
    .main-content {
        padding: 12px;
    }

    .container {
        margin: 12px;
    }

    header {
        padding: 24px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    main {
        padding: 24px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }
}

/* Tool Call Styling */
.tool-call-details {
    margin-bottom: 12px;
}

.tool-call-details:last-child {
    margin-bottom: 0;
}

.tool-call-details strong {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tool-call-details pre {
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    padding: 12px;
    margin: 0;
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--foreground);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.tool-call-result {
    margin-top: 12px;
}

.tool-call-result strong {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tool-call-result pre {
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    padding: 12px;
    margin: 0;
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--foreground);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.tool-call-result.error pre {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

.tool-call-result.success pre {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

.tool-call-body-inline {
    padding: 12px 0;
    font-size: 0.875rem;
}

.tool-call-body-inline .tool-call-details {
    margin-bottom: 16px;
}

.tool-call-body-inline .tool-call-details:last-child {
    margin-bottom: 0;
}
