/* ========================================
   Platform Responsive Styles
   Breakpoints: 992px / 768px / 576px
   ======================================== */

/* ---------- <=991px: Tablet & below ---------- */
@media (max-width: 991px) {
    /* Override 960px fixed container */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 15px;
        padding-right: 15px;
        box-sizing: border-box;
    }

    /* Navbar */
    .navbar {
        min-width: 0 !important;
        height: auto !important;
        padding-bottom: 0;
    }

    .navbar .nav-top {
        position: relative;
        top: auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 15px;
        gap: 10px;
    }

    .navbar .nav-top .navbar-nav {
        margin-left: auto;
    }

    .navbar .nav-text {
        position: relative;
        top: auto;
        padding: 5px 15px 10px;
        font-size: 18px;
    }

    .navbar .nav-menu {
        position: relative;
        bottom: auto;
        height: auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding: 0 10px;
        border-bottom: 1px solid rgba(255,255,255,.15);
    }

    .menu-item {
        margin-right: 24px;
        font-size: 13px;
    }

    /* Child menu */
    .child-menu {
        height: auto !important;
        padding: 10px 15px !important;
        overflow-x: auto;
        white-space: nowrap;
    }

    .child-menu a {
        display: inline-block;
        margin-bottom: 4px;
    }

    /* Content area */
    main.container {
        padding-left: 10px;
        padding-right: 10px;
    }

    main.container .main-r {
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    main.container .main-r-content {
        padding: 16px !important;
    }

    /* Tables: horizontal scroll */
    .table-responsive-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 10px;
    }

    table.table {
        min-width: 700px;
    }

    /* Forms */
    .form-group.row {
        flex-direction: column;
    }

    .form-group.row > .col-form-label {
        width: 100% !important;
        text-align: left;
        padding-left: 0 !important;
        margin-right: 0 !important;
        line-height: 1.5;
        margin-bottom: 4px;
    }

    .form-input .form-control,
    .form-input,
    .form-group .col-sm-6 {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .form-input .form-control {
        width: 100% !important;
    }

    .form-input {
        min-width: 0 !important;
    }

    /* Setting page: image upload form groups */
    .form-group.row[style*="height"] {
        height: auto !important;
    }

    .form-input .input-group {
        flex-wrap: nowrap;
        width: 100%;
    }

    .form-input .input-group .form-control {
        flex: 1;
        min-width: 0;
        width: auto !important;
    }

    .form-input .input-group .upload {
        flex-shrink: 0;
    }

    .form-input .input-group .upload a {
        white-space: nowrap;
        width: auto;
        padding: 0 10px;
    }

    .preview {
        width: 100%;
        max-width: 196px;
        margin-top: 8px;
    }

    .logo-preview {
        margin-top: 8px;
    }

    .logo-preview img {
        max-width: 100%;
        height: auto;
        max-height: 72px;
    }

    .form-input.offset-sm-3 {
        margin-left: 0 !important;
    }

    /* Modals */
    .change-password-modal .modal-dialog,
    .add-modal .modal-dialog,
    .clean-modal .modal-dialog {
        margin: 10px auto !important;
        max-width: calc(100vw - 20px) !important;
    }

    .change-password-modal .modal-content,
    .add-modal .modal-content,
    .clean-modal .modal-content {
        width: 100% !important;
    }

    .change-password-modal .form-input .form-control {
        width: 100% !important;
    }

    .col-form-label {
        float: none !important;
        width: 100% !important;
        text-align: left !important;
    }

    /* User edit page */
    .card-body {
        padding-left: 15px !important;
    }

    .auto-form-btn {
        margin-left: 0 !important;
    }

    .text-muted {
        width: auto !important;
    }

    /* App page */
    .my-app {
        height: auto !important;
        padding: 12px 10px !important;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
    }

    .my-app .add-app {
        flex-shrink: 0;
    }

    .app-info {
        position: static !important;
        top: auto !important;
        right: auto !important;
        height: auto !important;
        line-height: 1.5 !important;
        display: block;
        width: 100%;
        font-size: 12px;
    }

    .search {
        margin-left: auto;
        flex-shrink: 0;
    }

    .business {
        width: 160px;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Footer */
    footer .copyright {
        font-size: 12px;
        padding: 12px 10px !important;
    }
}

/* ---------- <=767px: Mobile ---------- */
@media (max-width: 767px) {
    /* Navbar hamburger visible */
    .navbar-toggler {
        display: block !important;
    }

    .navbar .nav-top {
        flex-wrap: wrap;
    }

    .navbar .nav-text {
        display: none;
    }

    .navbar .nav-menu {
        display: none;
        flex-direction: column;
        padding: 0;
        border-bottom: none;
    }

    .navbar .nav-menu.show {
        display: flex;
    }

    .navbar .nav-menu ul {
        padding: 0 !important;
    }

    .menu-item {
        float: none;
        display: block;
        padding: 10px 15px;
        margin-right: 0;
        border-bottom: 1px solid rgba(255,255,255,.1);
    }

    /* Child menu */
    .child-menu {
        padding: 8px 10px !important;
        margin-bottom: 5px;
    }

    .child-menu a {
        white-space: normal;
        height: auto;
        line-height: 1.5;
        padding: 6px 10px;
        display: inline-block;
        margin-bottom: 4px;
    }

    /* Content */
    main.container .main-r-content {
        padding: 10px !important;
        border: none !important;
    }

    /* me.html cards */
    .me-item {
        height: auto !important;
        margin-bottom: 15px;
        padding: 10px;
    }

    .me-item .left-info {
        float: none;
        padding-left: 10px;
        height: auto;
    }

    .me-item .title {
        margin-top: 8px;
    }

    .me-item img {
        float: none;
        display: block;
        margin: 10px auto 0;
        height: 80px;
        width: auto;
    }

    .row {
        padding: 15px 10px 30px !important;
        margin: 10px 0 0 0 !important;
    }

    /* Tables: card layout for app-list on mobile */
    .table-responsive-wrap:has(.app-list),
    .table-responsive-wrap:has(.account-list) {
        overflow-x: visible !important;
        min-width: 0 !important;
    }

    .app-list {
        table-layout: auto !important;
        min-width: 0 !important;
    }

    .table-responsive-wrap {
        overflow-x: visible;
    }

    .app-list colgroup {
        display: none;
    }

    .app-list thead {
        display: none;
    }

    .app-list tbody tr {
        display: block;
        border: 1px solid #f0f0f0;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
        background: #fff;
    }

    .app-list tbody td {
        display: block;
        height: auto !important;
        line-height: 1.6 !important;
        padding: 4px 0 !important;
        border-top: none !important;
    }

    /* Col 1: spacer — hide */
    .app-list tbody td:first-child {
        display: none;
    }

    /* Col 2: ID */
    .app-list tbody td:nth-child(2) {
        font-size: 12px;
        color: #999;
        padding-bottom: 2px !important;
    }

    .app-list tbody td:nth-child(2)::before {
        content: "ID: ";
    }

    /* Col 3: Name */
    .app-list tbody td:nth-child(3) {
        font-size: 15px;
        font-weight: bold;
        padding-bottom: 8px !important;
        border-bottom: 1px solid #f5f5f5;
        margin-bottom: 8px;
    }

    /* Col 4: Domain/URL */
    .app-list tbody td:nth-child(4) {
        padding-bottom: 8px !important;
    }

    .app-list tbody td:nth-child(4) .input-group {
        flex-wrap: nowrap;
    }

    .app-list tbody td:nth-child(4) .business {
        width: auto;
        flex: 1;
        min-width: 0;
        font-size: 12px;
        margin-top: 0;
    }

    .app-list tbody td:nth-child(4) .copybtn {
        flex-shrink: 0;
        margin-top: 0;
    }

    /* Col 5: Operate buttons */
    .app-list tbody td.operate,
    .app-list tbody td:last-child {
        padding-top: 8px !important;
        border-top: 1px solid #f5f5f5 !important;
        white-space: nowrap;
    }

    .operate a {
        margin-right: 8px !important;
        height: 32px !important;
        width: 32px !important;
    }

    .operate a img {
        height: 18px !important;
        width: 18px !important;
    }

    /* App header bar */
    .my-app {
        padding: 10px 8px;
    }

    .add-app {
        margin-bottom: 0;
    }

    .app-info {
        font-size: 11px;
    }

    .search input {
        width: 120px !important;
    }

    /* Account-list: card layout on mobile */
    .account-list {
        table-layout: auto !important;
        min-width: 0 !important;
    }

    .account-list colgroup {
        display: none;
    }

    .account-list thead {
        display: none;
    }

    .account-list tbody tr {
        display: block;
        border: 1px solid #f0f0f0;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
        background: #fff;
    }

    .account-list tbody td {
        display: block;
        height: auto !important;
        line-height: 1.6 !important;
        padding: 4px 0 !important;
        border-top: none !important;
    }

    /* Col 1: spacer — hide */
    .account-list tbody td:first-child {
        display: none;
    }

    /* Col 2: ID */
    .account-list tbody td:nth-child(2) {
        font-size: 12px;
        color: #999;
        padding-bottom: 2px !important;
    }

    .account-list tbody td:nth-child(2)::before {
        content: "ID: ";
    }

    /* Col 3: Account name + remark */
    .account-list tbody td:nth-child(3) {
        font-size: 15px;
        font-weight: bold;
        padding-bottom: 8px !important;
        border-bottom: 1px solid #f5f5f5;
        margin-bottom: 4px;
    }

    .account-list tbody td:nth-child(3) .remark {
        font-weight: normal;
        font-size: 12px;
        color: #999;
        margin-top: 2px !important;
        line-height: 1.4 !important;
    }

    /* Col 4: max count */
    .account-list tbody td:nth-child(4) {
        font-size: 13px;
    }

    .account-list tbody td:nth-child(4)::before {
        content: "可创建: ";
        color: #999;
        font-weight: normal;
    }

    /* Col 5: created count */
    .account-list tbody td:nth-child(5) {
        font-size: 13px;
        padding-bottom: 8px !important;
        border-bottom: 1px solid #f5f5f5;
    }

    .account-list tbody td:nth-child(5)::before {
        content: "已创建: ";
        color: #999;
        font-weight: normal;
    }

    /* Col 6: expire time */
    .account-list tbody td:nth-child(6) {
        font-size: 13px;
        padding-bottom: 8px !important;
    }

    .account-list tbody td:nth-child(6)::before {
        content: "有效期: ";
        color: #999;
        font-weight: normal;
    }

    /* Col 7: Operate buttons */
    .account-list tbody td.operate,
    .account-list tbody td:last-child {
        padding-top: 8px !important;
        border-top: 1px solid #f5f5f5 !important;
        white-space: nowrap;
    }

    /* Account search bar */
    .account-search {
        width: 100% !important;
        padding: 8px 0 !important;
        height: auto !important;
    }

    .account-search input {
        width: 100% !important;
        margin-top: 0 !important;
    }

    .account-search .btn {
        right: 4px !important;
        top: 16px !important;
    }

    /* recycle-list and subapp-list keep horizontal scroll */
    .recycle-list,
    .subapp-list {
        min-width: 600px;
        font-size: 12px;
    }

    .recycle-list tbody td,
    .subapp-list tbody td {
        height: auto !important;
        line-height: 1.5 !important;
        padding: 8px 4px !important;
    }

    /* Forms */
    .card-body {
        padding: 15px !important;
    }

    .new-account {
        padding: 0 15px;
        font-size: 12px;
    }

    .account-info {
        float: none;
        display: block;
        margin-top: 4px;
    }

    .auto-form-btn {
        margin-left: 0 !important;
        width: 80px;
    }

    /* Modal */
    .change-password-modal .modal-dialog {
        margin-top: 5% !important;
    }

    .modal-title {
        font-size: 14px;
    }

    /* Setting page */
    .form-group.row {
        margin-bottom: 12px;
    }

    /* User edit */
    .account-label span {
        width: auto;
    }

    label.required.account-label::before {
        left: auto !important;
        right: -10px;
    }

    /* Permission checkboxes wrap */
    .custom-control {
        display: inline-flex !important;
        margin-right: 12px !important;
        margin-bottom: 8px;
    }

    .custom-control-description {
        font-size: 13px;
    }

    /* Expire time form-inline */
    .form-inline {
        flex-wrap: wrap;
        gap: 8px;
    }

    .form-inline .form-control {
        flex: 1;
        min-width: 0;
        width: auto !important;
    }

    .form-inline .custom-control {
        margin-left: 0 !important;
    }

    /* Pagination */
    .pagination li {
        margin: 2px !important;
    }

    .pagination .disabled span,
    .pagination li span,
    .pagination li a {
        height: 28px !important;
        width: 28px !important;
        font-size: 12px;
        line-height: 28px;
        padding: 0 !important;
    }
}

/* ---------- <=575px: Small mobile ---------- */
@media (max-width: 575px) {
    .navbar-brand img {
        height: 22px !important;
    }

    /* me.html: full width cards */
    .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Tables: even more compact (non app-list/account-list) */
    .recycle-list,
    .subapp-list {
        min-width: 500px;
    }

    .business {
        width: 100px;
    }

    /* Modals on small screens */
    .change-password-modal .modal-dialog {
        margin: 5px !important;
    }
}

/* ---------- Login page responsive (standalone) ---------- */
@media (max-width: 767px) {
    #app {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
    }

    .opacity {
        position: relative !important;
    }

    .login-card {
        position: relative !important;
        width: 92% !important;
        max-width: 400px;
        height: auto !important;
        margin: 0 auto !important;
    }

    .login-form {
        width: 100% !important;
        height: auto !important;
        float: none;
        padding: 30px 25px 20px;
        border-radius: 0 0 20px 20px;
    }

    .login-img {
        min-height: 80px;
    }

    .logo {
        left: 15px !important;
        top: 15px !important;
        height: 30px;
    }

    .footer {
        position: relative !important;
        bottom: auto !important;
        padding: 15px 10px;
        font-size: 12px;
    }

    .username, .password, .captcha_code {
        margin-bottom: 14px;
    }

    .form-title {
        font-size: 20px;
        margin-bottom: 24px;
    }

    /* Reset password modal on mobile */
    #resetPassword .modal-dialog {
        margin: 10px auto;
        max-width: calc(100vw - 20px);
    }
}

/* ---------- Hamburger toggle button ---------- */
.navbar-toggler {
    display: none;
    background: none;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    color: #fff;
    font-size: 18px;
    line-height: 1;
}

.navbar-toggler:hover {
    border-color: rgba(255,255,255,.8);
}

/* ---------- Print ---------- */
@media print {
    .navbar,
    .nav-menu,
    .child-menu,
    footer,
    .pagination {
        display: none !important;
    }

    main.container .main-r-content {
        padding: 0;
        border: none;
    }
}
