/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --brand: #0078d4;
    --brand-hover: #106ebe;
    --brand-active: #005a9e;
    --bg-primary: #f5f5f5;
    --bg-surface: #ffffff;
    --bg-surface-hover: #fafafa;
    --bg-subtle: #f0f0f0;
    --bg-accent: #eff6fc;
    --text-primary: #242424;
    --text-secondary: #616161;
    --text-tertiary: #8a8a8a;
    --text-on-brand: #ffffff;
    --border-default: #e0e0e0;
    --border-subtle: #ebebeb;
    --border-strong: #c4c4c4;
    --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.04), 0 0 2px rgba(0, 0, 0, 0.06);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 0 2px rgba(0, 0, 0, 0.06);
    --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.12), 0 0 4px rgba(0, 0, 0, 0.06);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-base: 14px;
    --font-sm: 12px;
    --font-xs: 11px;
    --font-lg: 16px;
    --font-xl: 20px;
    --font-xxl: 24px;
    --transition: 0.15s ease;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: var(--font-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Login View ===== */
#loginView {
    min-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-elevated);
    padding: 44px 40px 40px;
}

.login-brand {
    margin-bottom: 28px;
}

.login-brand h1 {
    font-size: var(--font-xxl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-brand p {
    font-size: var(--font-base);
    color: var(--text-secondary);
}

.login-box {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    font-size: var(--font-base);
    font-family: inherit;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    outline: none;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
}

.form-group input::placeholder {
    color: var(--text-tertiary);
}

.login-box button[type="button"],
.login-box button[type="submit"],
.login-box > button {
    width: 100%;
    padding: 10px 24px;
    font-size: var(--font-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--text-on-brand);
    background-color: var(--brand);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition);
    margin-top: 4px;
}

.login-box button:hover {
    background-color: var(--brand-hover);
}

.login-box button:active {
    background-color: var(--brand-active);
}

.login-box button:disabled {
    background-color: var(--border-default);
    color: var(--text-tertiary);
    cursor: not-allowed;
}

/* ===== Error Banner ===== */
.error {
    padding: 10px 14px;
    background-color: #fde7e9;
    color: #b10e1c;
    border: 1px solid #f1bbbc;
    border-radius: var(--radius-sm);
    font-size: var(--font-sm);
    margin-top: 16px;
}

#error {
    margin-bottom: 16px;
    margin-top: 0;
}

/* ===== Search View ===== */
.header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.header-row h1 {
    font-size: var(--font-xxl);
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    margin: 0;
}

#userInfo {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

#userInfo::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #107c10;
    flex-shrink: 0;
}

.logout-btn {
    padding: 6px 14px;
    font-size: var(--font-sm);
    font-family: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.logout-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* ===== Search Box ===== */
.search-box {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.search-box input {
    flex: 1;
    padding: 10px 14px;
    font-size: var(--font-base);
    font-family: inherit;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    outline: none;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
}

.search-box input::placeholder {
    color: var(--text-tertiary);
}

.search-box button {
    padding: 10px 20px;
    font-size: var(--font-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--text-on-brand);
    background-color: var(--brand);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition);
    white-space: nowrap;
}

.search-box button:hover {
    background-color: var(--brand-hover);
}

.search-box button:active {
    background-color: var(--brand-active);
}

/* ===== Loading ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    color: var(--text-secondary);
    font-size: var(--font-base);
}

.loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-default);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Results ===== */
.no-results {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    font-size: var(--font-base);
}

.result-count {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 500;
}

.document-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ===== Document Card ===== */
.document-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.document-card:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-default);
    box-shadow: var(--shadow-card);
}

.document-card:active {
    background: var(--bg-subtle);
}

.doc-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-accent);
    border-radius: var(--radius-sm);
}

.doc-info {
    flex: 1;
    min-width: 0;
}

.doc-title {
    font-size: var(--font-base);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.doc-meta {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
}

.doc-meta span {
    display: inline;
}

.doc-meta span:not(:last-child)::after {
    content: '\00b7';
    margin: 0 6px;
    color: var(--border-strong);
    font-weight: 700;
}

.doc-location {
    font-size: var(--font-xs);
    color: var(--text-tertiary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-action {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.document-card:hover .doc-action {
    opacity: 1;
}

.open-btn {
    padding: 6px 14px;
    font-size: var(--font-sm);
    font-weight: 600;
    font-family: inherit;
    color: var(--brand);
    background: transparent;
    border: 1px solid var(--brand);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.open-btn:hover {
    background: var(--brand);
    color: var(--text-on-brand);
}

/* ===== Viewer Panel ===== */
.viewer-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 70%;
    height: 100%;
    background: var(--bg-surface);
    box-shadow: -2px 0 24px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
}

.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    gap: 12px;
}

.viewer-header span {
    font-weight: 600;
    font-size: var(--font-base);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: all var(--transition);
}

.close-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.viewer-frame {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}

/* ===== Dark Theme (Teams) ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --brand: #479ef5;
        --brand-hover: #62abf5;
        --brand-active: #3b8de0;
        --bg-primary: #1b1b1b;
        --bg-surface: #292929;
        --bg-surface-hover: #303030;
        --bg-subtle: #333333;
        --bg-accent: #1a3a5c;
        --text-primary: #f5f5f5;
        --text-secondary: #adadad;
        --text-tertiary: #8a8a8a;
        --text-on-brand: #000000;
        --border-default: #404040;
        --border-subtle: #363636;
        --border-strong: #5c5c5c;
        --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.2);
        --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.3);
        --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    .error {
        background-color: #442726;
        color: #f1bbbc;
        border-color: #6b3535;
    }

    .form-group input {
        background: #333333;
    }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .container {
        padding: 16px;
    }

    .login-card {
        padding: 28px 24px 24px;
    }

    .header-row {
        flex-wrap: wrap;
    }

    .header-row h1 {
        font-size: var(--font-xl);
    }

    .viewer-panel {
        width: 100%;
    }

    .doc-action {
        opacity: 1;
    }
}
