:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --card: #0f3460;
    --accent: #e94560;
    --text: #eee;
    --text-dim: #aaa;
    --border: #2a2a4a;
    --success: #4caf50;
    --radius: 10px;
}

[data-theme="light"] {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --card: #e4e6e9;
    --text: #1a1a2e;
    --text-dim: #555;
    --border: #ccc;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.hidden { display: none !important; }
.hp { position: absolute; left: -9999px; opacity: 0; height: 0; width: 0; }

/* Login */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    padding: 2.5rem 2rem;
    border-radius: var(--radius);
    text-align: center;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
    position: relative;
}

.logo {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: .3rem;
}

.subtitle {
    color: var(--text-dim);
    font-size: .9rem;
    margin-bottom: 1.5rem;
}

.ttl-notice {
    color: var(--text-dim);
    font-size: .75rem;
    margin-top: -.2rem;
    margin-bottom: 1.5rem;
    font-weight: 400;
    opacity: .7;
}

.ttl-badge {
    font-size: .65rem;
    background: var(--accent);
    color: #fff;
    padding: .15rem .45rem;
    border-radius: 20px;
    vertical-align: middle;
    font-weight: 600;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: .8rem;
}

#login-form input {
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    text-align: center;
    outline: none;
}

#room-code {
    -webkit-text-security: disc;
    text-security: disc;
}

#login-form input:focus {
    border-color: var(--accent);
}

#login-form button {
    padding: .75rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .2s;
}

#login-form button:hover { opacity: .85; }

/* Workspace */
#workspace-view {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .8rem 1.2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.logo-small {
    font-size: 1.3rem;
    font-weight: 700;
}


.header-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.btn-theme {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    padding: 0;
}

.btn-theme:hover { color: var(--accent); border-color: var(--accent); }

.btn-theme-login {
    position: absolute;
    top: .8rem;
    right: .8rem;
}

main {
    flex: 1;
    padding: 1rem;
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}

/* Input section */
.input-section {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 1rem;
}

#clip-text {
    width: 100%;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: .95rem;
    resize: vertical;
    font-family: inherit;
    outline: none;
}

#clip-text:focus { border-color: var(--accent); }

.btn-primary {
    padding: .65rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-end;
    transition: opacity .2s;
}

.btn-primary:hover { opacity: .85; }

/* Upload */
.upload-section {
    margin-bottom: 1.2rem;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    color: var(--text-dim);
    font-size: .9rem;
    transition: border-color .2s, background .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    flex-wrap: wrap;
}

.drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, .08);
}

.file-label {
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
}

.size-hint {
    font-size: .8rem;
}

/* Upload progress */
.upload-progress-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: .4rem;
    align-items: center;
}

.upload-file-name {
    font-size: .85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.upload-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.upload-bar-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: 3px;
    transition: width .15s;
}

.upload-pct {
    font-size: .8rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* Search + Refresh */
.search-section {
    margin-bottom: 1rem;
    display: flex;
    gap: .5rem;
}

#search-input {
    flex: 1;
    min-width: 0;
    padding: .6rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: .85rem;
    font-family: inherit;
    outline: none;
}

#search-input:focus { border-color: var(--accent); }

#search-input::placeholder { color: var(--text-dim); }

.btn-refresh {
    padding: .6rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all .2s;
    flex-shrink: 0;
}

.btn-refresh:hover { border-color: var(--accent); color: var(--accent); }

/* Items */
.items-list {
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .8rem;
    position: relative;
}

.item-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: .9rem;
    line-height: 1.5;
    margin-bottom: .5rem;
    max-height: 200px;
    overflow-y: auto;
}

.item-file {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .9rem;
}

.item-file .file-icon {
    font-size: 1.5rem;
}

.item-file .file-info {
    flex: 1;
    min-width: 0;
}

.item-file .file-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-file .file-size {
    color: var(--text-dim);
    font-size: .8rem;
}

.item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: .4rem;
}

.item-time {
    color: var(--text-dim);
    font-size: .75rem;
}

.item-actions {
    display: flex;
    gap: .4rem;
}

.item-actions button {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: .25rem .6rem;
    border-radius: 6px;
    font-size: .78rem;
    cursor: pointer;
    transition: all .2s;
}

.item-actions button:hover {
    color: var(--text);
    border-color: var(--text);
}

.item-actions .btn-delete:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    color: var(--text);
    padding: .6rem 1.2rem;
    border-radius: var(--radius);
    font-size: .9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    z-index: 1000;
    transition: opacity .3s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

/* Responsive */
@media (max-width: 480px) {
    body {
        -webkit-text-size-adjust: 100%;
        padding-top: env(safe-area-inset-top, 0);
    }

    .login-card {
        padding: 2rem 1.5rem;
        width: 95%;
    }

    header {
        padding: .6rem .8rem;
        padding-top: calc(.6rem + env(safe-area-inset-top, 0));
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .logo-small { font-size: 1.1rem; }

    main {
        padding: .6rem;
        padding-bottom: calc(.6rem + env(safe-area-inset-bottom, 0));
    }

    #clip-text {
        font-size: 16px;
        padding: .65rem;
        rows: 2;
    }

    .btn-primary {
        align-self: stretch;
        padding: .75rem;
        font-size: 1rem;
    }

    .drop-zone {
        padding: .8rem .6rem;
        font-size: .82rem;
        min-height: 48px;
    }

    .search-section { gap: .4rem; }

    #search-input {
        font-size: 16px;
        padding: .55rem .7rem;
    }

    .btn-refresh {
        padding: .55rem .75rem;
        font-size: 1rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .item { padding: .65rem; }

    .item-text {
        font-size: .85rem;
        max-height: 150px;
    }

    .item-meta { flex-wrap: wrap; gap: .3rem; }

    .item-actions button {
        padding: .35rem .7rem;
        font-size: .8rem;
        min-height: 36px;
    }

    .btn-theme {
        min-width: 36px;
        min-height: 36px;
    }

    .toast {
        bottom: calc(1rem + env(safe-area-inset-bottom, 0));
        left: .8rem;
        right: .8rem;
        transform: none;
        text-align: center;
    }

    #login-form input {
        font-size: 16px;
        padding: .85rem 1rem;
    }

    #login-form button {
        padding: .85rem;
        font-size: 1.05rem;
    }
}
