:root {
    --bg-color: #0d1117;
    --sidebar-bg: #161b22;
    --card-bg: #21262d;
    --card-hover: #30363d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --border: #30363d;
    --radius: 12px;
    --transition: cubic-bezier(0.4, 0, 0.2, 1) 0.3s;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: grid;
    grid-template-columns: 300px 1fr 0px;
    height: 100vh;
    transition: grid-template-columns 0.4s var(--transition);
}

.app-container.preview-open {
    grid-template-columns: 300px 1fr 600px;
}

/* Sidebar */
.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    z-index: 10;
}

.brand h1 {
    font-size: 1.5rem;
    margin: 0;
    background: linear-gradient(45deg, #58a6ff, #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.search-box input {
    width: 100%;
    padding: 12px 16px;
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
    box-sizing: border-box;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.filters-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.filter-group label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

.filter-group select {
    width: 100%;
    background: #0d1117;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px;
    padding-right: 32px;
    /* Space for arrow */
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    font-size: 0.9rem;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

.stats {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
}

/* Main Content */
.main-content {
    padding: 30px;
    overflow-y: auto;
    background: radial-gradient(circle at top right, #1f242d 0%, #0d1117 40%);
}

.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding-bottom: 50px;
}

.doc-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease-out;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
    background: var(--card-hover);
}

.doc-title {
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.4;
    word-break: break-word;
}

.doc-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.05);
    /* Fallback */
    border: 1px solid transparent;
}

.badge-tag {
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
}

.doc-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Preview Panel */
.preview-panel {
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    height: 100%;
    /* Explicit height */
}

.preview-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(22, 27, 34, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.preview-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#closePreview {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #30363d;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

#closePreview:hover {
    background: #c9d1d9;
    color: #000;
}

/* Action Buttons */
.preview-actions {
    display: flex;
    gap: 12px;
    margin-left: auto;
    margin-right: 20px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon:hover {
    background: var(--card-hover);
    border-color: var(--text-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-danger {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

.btn-danger:hover {
    color: #ff4040;
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.preview-content {
    flex: 1;
    background: #21262d;
    /* Slightly lighter than black for contrast */
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Safari Fix */
    overflow: hidden;
}

iframe {
    width: 100%;
    height: 100%;
    flex: 1;
    border: none;
    min-height: 0;
    /* Safari Fix */
    display: block;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #58a6ff;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.modal {
    background: #161b22;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-body {
    padding: 20px;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.form-group input {
    width: 100%;
    background: #0d1117;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    color: white;
    outline: none;
    box-sizing: border-box;
    font-size: 16px;
    /* Prevents zoom on iOS */
}

.form-group input:focus {
    border-color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}

#closeModal {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* Safari Fixes */
select {
    -webkit-appearance: none;
    appearance: none;
    background-color: #0d1117;
}

/* Tag Chips Input (V9 Enhanced) */
.tag-input-container {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 50px;
    cursor: text;
    box-sizing: border-box;
    transition: border 0.2s;
}

.tag-input-container:focus-within {
    border-color: var(--accent);
}

.tag-input-container input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    flex: 1;
    min-width: 100px;
    padding: 6px 0;
    margin: 0;
}

.tag-chip {
    background: rgba(88, 166, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(88, 166, 255, 0.4);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    animation: fadeIn 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tag-chip span {
    cursor: pointer;
    font-size: 1.2em;
    opacity: 0.7;
    transition: all 0.2s;
    line-height: 1;
    display: flex;
    align-items: center;
}

.tag-chip span:hover {
    opacity: 1;
    color: #ff6b6b;
    transform: scale(1.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Dedicated Drop Shield */
.drop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(13, 17, 23, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.drop-overlay.active {
    display: flex;
}

.drop-message {
    text-align: center;
    color: var(--text-primary);
    font-size: 2rem;
    font-weight: bold;
    pointer-events: none;
}

.warning-box {
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: none;
    /* Hidden by default */
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 500;
}

.warning-box.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}