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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

a { color: #186ade; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Auth pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f2f5 0%, #e8ecf1 100%);
}

.auth-card {
    background: #fff;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 420px;
}

.auth-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.subtitle { color: #666; margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-link { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: #666; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-weight: 500; font-size: 0.9rem; }
.form-group input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
.form-group input:focus { outline: none; border-color: #186ade; }

.input-group { display: flex; gap: 0.5rem; }
.input-group input { flex: 1; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.btn-primary { background: #186ade; color: #fff; }
.btn-primary:hover { background: #1456b8; }
.btn-secondary { background: #e5e7eb; color: #333; }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-danger-text { color: #dc2626; padding: 0.25rem 0.5rem; }
.btn-danger-text:hover { color: #b91c1c; text-decoration: underline; }
.btn-text { background: none; color: #666; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.upload-btn { cursor: pointer; }

/* App layout with sidebar */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: #fff;
    color: #333;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e8e8e8;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    font-size: 1rem;
    border-bottom: 1px solid #f0f0f0;
    color: #1a1a1a;
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    color: #555;
    text-decoration: none;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.sidebar-item:hover {
    background: #f5f7fa;
    color: #186ade;
    text-decoration: none;
}

.sidebar-item.active {
    background: #e8f0fe;
    color: #186ade;
    font-weight: 500;
}

.sidebar-item.sub {
    padding-left: 2.2rem;
    font-size: 0.9rem;
}

.sidebar-group {
    margin-top: 0.35rem;
}

.sidebar-group-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #555;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.sidebar-group-title:hover {
    background: #f5f7fa;
    color: #186ade;
}

.sidebar-group.open .sidebar-group-title {
    color: #186ade;
}

.sidebar-group-label {
    flex: 1;
}

.sidebar-caret {
    font-size: 0.75rem;
    color: #999;
    transition: transform 0.2s;
    transform: rotate(-90deg);
}

.sidebar-group.open .sidebar-caret {
    transform: rotate(0deg);
}

.sidebar-dropdown {
    display: none;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.15rem 0 0.25rem;
}

.sidebar-group.open .sidebar-dropdown {
    display: flex;
}

.sidebar-icon {
    font-size: 1.1rem;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main-area .navbar {
    flex-shrink: 0;
}

.main-area .container {
    flex: 1;
    max-width: none;
    margin: 0;
    padding: 1.5rem 2rem;
}

/* Navbar */
.navbar {
    background: #fff;
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.nav-brand { font-weight: 600; font-size: 1.1rem; }
.nav-brand a { color: #333; }
.nav-actions { display: flex; align-items: center; gap: 1rem; }

/* Container */
.container { max-width: 960px; margin: 2rem auto; padding: 0 1.5rem; }

.panel {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    margin-bottom: 1.5rem;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
}

.panel-header h3 {
    font-size: 1.05rem;
}

.panel-desc {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 1rem;
}

.device-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    min-width: 200px;
}

.import-list {
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.import-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: #f9fafb;
}

.import-item label {
    flex: 1;
    cursor: pointer;
    font-size: 0.9rem;
}

.import-item.disabled {
    opacity: 0.5;
}

.modal-content.wide {
    max-width: 560px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.4rem; }

/* Device cards */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.device-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.device-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.device-header h3 { font-size: 1.05rem; }
.device-info { font-size: 0.85rem; color: #666; margin-bottom: 1rem; }
.device-info p { margin-bottom: 0.25rem; }
.device-info code { background: #f3f4f6; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.8rem; }
.device-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.status { font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 999px; font-weight: 500; }
.status-0 { background: #fef3c7; color: #92400e; }
.status-1 { background: #d1fae5; color: #065f46; }
.status-2 { background: #fee2e2; color: #991b1b; }

/* Audio list */
.audio-list { display: flex; flex-direction: column; gap: 0.75rem; }
.audio-item {
    background: #fff;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    flex-wrap: wrap;
    gap: 0.75rem;
}
.audio-name { font-weight: 500; margin-right: 0.5rem; }
.audio-meta { font-size: 0.8rem; color: #888; display: block; margin-top: 0.2rem; }
.audio-actions { display: flex; align-items: center; gap: 0.75rem; }
.audio-actions audio { height: 32px; }
.badge { background: #186ade; color: #fff; font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 4px; }

/* Provision */
.provision-steps { display: flex; flex-direction: column; gap: 1.5rem; }
.step {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.step-num {
    width: 36px; height: 36px;
    background: #186ade;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}
.step-content h3 { margin-bottom: 0.5rem; }
.step-content p { color: #666; font-size: 0.9rem; margin-bottom: 0.75rem; }
.hint { font-size: 0.85rem; color: #888; }

.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.api-info { background: #fff; padding: 1rem 1.25rem; border-radius: 10px; margin-bottom: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.api-info p { font-size: 0.9rem; color: #666; margin-bottom: 0.5rem; }

/* Modal */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-content {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 440px;
}
.modal-content h3 { margin-bottom: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }

/* Empty & Messages */
.empty-state { text-align: center; padding: 3rem; color: #888; }
.message { margin-top: 1rem; padding: 0.75rem; border-radius: 8px; font-size: 0.9rem; }
.message.error { background: #fee2e2; color: #991b1b; }
.message.success { background: #d1fae5; color: #065f46; }
.message.toast {
    position: fixed; bottom: 2rem; right: 2rem;
    z-index: 200; min-width: 280px; max-width: min(420px, calc(100vw - 2rem));
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
    line-height: 1.5;
    word-break: break-word;
}
.message.toast:empty { display: none !important; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.75rem 0.6rem;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}
.admin-table th {
    color: #666;
    font-weight: 600;
    background: #fafafa;
}
.admin-actions {
    display: flex;
    gap: 0.5rem;
}
.muted { color: #888; font-size: 0.8rem; }
