/* Reset และ Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #4facfe 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px;
}

/* Header */
header {
    margin-bottom: 20px;
    color: white;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.header-title {
    text-align: left;
}

.header-title h1 {
    font-size: 2rem;
    margin-bottom: 6px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.25);
}

.header-title p {
    font-size: 1rem;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    gap: 12px;
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .header-title {
        text-align: center;
    }
}

/* Cards */
.card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    margin-bottom: 18px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    /* transform: translateY(-3px); */
    box-shadow: 0 10px 28px rgba(0,0,0,0.12);
}

.card-header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

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

.card-body {
    padding: 16px;
}

/* Droplet Info */
.droplet-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

/* Droplet Selector */
.droplet-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.droplet-selector label {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
}

.droplet-selector select {
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.droplet-selector select:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.2);
}

.droplet-selector select:hover {
    border-color: #4facfe;
}

.droplet-summary {
    background: linear-gradient(145deg, #e8f4fd 0%, #d1ecf1 100%);
    padding: 10px 14px;
    border-radius: 8px;
    border-left: 4px solid #4facfe;
    font-weight: 500;
    color: #2c5282;
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.15);
}

.droplet-summary span {
    color: #2a5298;
    font-weight: 600;
}

.info-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: linear-gradient(145deg, #f8faff 0%, #e8f4fd 100%);
    border-radius: 8px;
    border-left: 4px solid #4facfe;
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.1);
}

.info-item label {
    font-weight: 600;
    color: #666;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.info-item span {
    font-size: 1rem;
    color: #333;
    font-weight: 500;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 18px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.status-badge.active {
    background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%);
    color: #22543d;
    border: 1px solid #9ae6b4;
    box-shadow: 0 2px 8px rgba(154, 230, 180, 0.3);
}

.status-badge.off {
    background: linear-gradient(135deg, #fed7d7 0%, #fc8181 100%);
    color: #742a2a;
    border: 1px solid #fc8181;
    box-shadow: 0 2px 8px rgba(252, 129, 129, 0.3);
}

.status-badge.new {
    background: linear-gradient(135deg, #fefcbf 0%, #f6e05e 100%);
    color: #744210;
    border: 1px solid #f6e05e;
    box-shadow: 0 2px 8px rgba(246, 224, 94, 0.3);
}

/* Buttons */
.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    user-select: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(79, 172, 254, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #3182ce 0%, #2b77e6 100%);
    box-shadow: 0 5px 16px rgba(79, 172, 254, 0.5);
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(72, 187, 120, 0.35);
}

.btn-success:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
    box-shadow: 0 5px 16px rgba(72, 187, 120, 0.5);
}

.btn-danger {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(245, 101, 101, 0.35);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%);
    box-shadow: 0 5px 16px rgba(245, 101, 101, 0.5);
}

.btn-secondary {
    background: linear-gradient(135deg, #718096 0%, #4a5568 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(113, 128, 150, 0.35);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    box-shadow: 0 5px 16px rgba(113, 128, 150, 0.5);
}

.btn-outline {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
    box-shadow: 0 3px 12px rgba(255, 255, 255, 0.2);
}

.btn-info {
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
    color: white;
    border: 2px solid transparent;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-info:hover {
    background: linear-gradient(135deg, #138496 0%, #117a8b 100%);
    box-shadow: 0 5px 16px rgba(23, 162, 184, 0.4);
    transform: translateY(-1px);
    text-decoration: none;
    color: white;
}

/* Control Buttons */
.control-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.control-buttons .btn {
    flex: 0 0 auto; /* don't stretch */
    min-width: 120px;
    justify-content: center;
    font-size: 0.95rem;
    padding: 10px 16px;
}

/* Action Status */
.action-status {
    background: linear-gradient(145deg, #e6fffa 0%, #b2f5ea 100%);
    border: 1px solid #81e6d9;
    border-radius: 8px;
    padding: 14px;
    margin-top: 14px;
    box-shadow: 0 4px 12px rgba(129, 230, 217, 0.2);
}

.action-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: #234e52;
    font-weight: 500;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4facfe, #00f2fe, #4facfe);
    border-radius: 4px;
    animation: progress-animation 2s infinite;
}

@keyframes progress-animation {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* Auto Refresh */
.auto-refresh-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auto-refresh-controls label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    cursor: pointer;
}

.auto-refresh-controls input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #4facfe;
}

.auto-refresh-status {
    font-size: 0.9rem;
    color: #666;
    font-style: italic;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    position: relative;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.alert-error {
    background: linear-gradient(135deg, #fed7d7 0%, #fbb6ce 100%);
    color: #742a2a;
    border: 1px solid #fbb6ce;
    box-shadow: 0 4px 12px rgba(251, 182, 206, 0.3);
}

.alert-success {
    background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%);
    color: #22543d;
    border: 1px solid #9ae6b4;
    box-shadow: 0 4px 12px rgba(154, 230, 180, 0.3);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

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

/* Loading */
.loading {
    text-align: center;
    padding: 24px;
    color: white;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 14px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 24px;
    padding: 14px;
    font-size: 13px;
    color: white;
    opacity: 0.5;
}

footer .fas.fa-heart {
    color: #f093fb;
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Small Buttons */
.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

/* Admin Page */
.admin-login-card {
    max-width: 440px;
    margin: 40px auto 18px;
}

.admin-login-card .card-body p {
    color: #555;
    margin-bottom: 12px;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.admin-tab {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.admin-tab:hover {
    background: rgba(255, 255, 255, 0.22);
}

.admin-tab.active {
    background: white;
    color: #1e3c72;
    border-color: white;
}

/* Activity Log */
.activity-filters {
    display: grid;
    grid-template-columns: 220px 150px 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.activity-filters select,
.activity-filters input {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #333;
    background: white;
    min-width: 0;
}

.activity-filters select:focus,
.activity-filters input:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.2);
}

#activity-count {
    margin-bottom: 8px;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.activity-item {
    display: grid;
    grid-template-columns: 150px 190px 1fr 210px;
    gap: 12px;
    align-items: start;
    padding: 9px 12px;
    background: #f8faff;
    border-left: 4px solid #4facfe;
    border-radius: 8px;
    font-size: 0.88rem;
}

.activity-item.failed {
    background: #fff5f5;
    border-left-color: #f56565;
}

.activity-time {
    color: #666;
    font-variant-numeric: tabular-nums;
}

.activity-action {
    font-weight: 600;
    color: #2c5282;
}

.activity-item.failed .activity-action {
    color: #c53030;
}

.activity-detail {
    color: #333;
    overflow-wrap: anywhere;
}

.activity-who {
    color: #333;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.activity-device {
    color: #888;
    font-size: 0.8rem;
}

.activity-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.activity-badge.failed {
    background: #fed7d7;
    color: #742a2a;
}

.activity-badge.role-admin {
    background: #e9d8fd;
    color: #44337a;
}

.activity-badge.role-user {
    background: #bee3f8;
    color: #2a4365;
}

.activity-badge.role-guest {
    background: #e2e8f0;
    color: #4a5568;
}

.activity-more {
    text-align: center;
    margin-top: 12px;
}

.manage-item.missing {
    border-left-color: #f56565;
}

.manage-item-warning {
    font-size: 0.82rem;
    color: #c53030;
    font-weight: 600;
}

/* Droplet List Manager */
.manage-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.manage-count {
    color: #666;
    font-weight: 600;
}

.manage-notice {
    background: linear-gradient(135deg, #fffff0 0%, #fefcbf 100%);
    border-left: 4px solid #f6e05e;
    color: #744210;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.manage-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.manage-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: linear-gradient(145deg, #f8faff 0%, #e8f4fd 100%);
    border-left: 4px solid #4facfe;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.1);
}

.manage-item-info {
    min-width: 0;
}

.manage-item-name {
    font-weight: 600;
    color: #333;
}

.manage-item-meta,
.manage-item-desc {
    font-size: 0.82rem;
    color: #666;
    overflow-wrap: anywhere;
}

.manage-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.manage-empty {
    text-align: center;
    color: #666;
    padding: 24px 12px;
    border: 2px dashed #e0e0e0;
    border-radius: 8px;
}

.manage-footnote {
    margin-top: 14px;
}

/* Form */
.droplet-form h3 {
    font-size: 1.05rem;
    color: #2a5298;
    margin-bottom: 14px;
    overflow-wrap: anywhere;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.form-group label {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    padding: 9px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #333;
    background: white;
    min-width: 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.2);
}

.form-group input[readonly] {
    background: #f3f4f6;
    color: #666;
    cursor: not-allowed;
}

.form-hint {
    font-size: 0.8rem;
    color: #888;
}

.input-row {
    display: flex;
    gap: 8px;
}

.input-row select {
    flex: 1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* Responsive Design */
@media (max-width: 860px) {
    .activity-item {
        grid-template-columns: 1fr 1fr;
    }

    .activity-detail,
    .activity-who {
        grid-column: 1 / -1;
    }

    .activity-filters {
        grid-template-columns: 1fr 1fr;
    }

    .activity-filters input {
        grid-column: 1 / -1;
    }
}

@media (max-width: 600px) {
    .admin-tabs {
        justify-content: center;
    }

    .activity-item {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .manage-item {
        flex-direction: column;
        align-items: stretch;
    }

    .manage-item-actions {
        justify-content: flex-end;
    }

    .input-row {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    .card-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .control-buttons {
        flex-direction: column;
    }
    
    .control-buttons .btn {
        width: 100%;
    }
    
    .droplet-info {
        grid-template-columns: 1fr;
    }
    
    .droplet-selector {
        gap: 10px;
    }
    
    .droplet-selector select {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .card-body {
        padding: 14px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
}